From 4f5feda6d73b5aad394662d638816c820ac85c09 Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Wed, 16 Oct 2024 16:40:45 +0300 Subject: [PATCH 1/7] Adding an error in case of a problem with the issue of assets, adding additional checks in transfer methods. --- itests/utilities/issue/issue.go | 4 ++ itests/utilities/transfer/transfer.go | 67 +++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/itests/utilities/issue/issue.go b/itests/utilities/issue/issue.go index 6b373f899..a12d11285 100644 --- a/itests/utilities/issue/issue.go +++ b/itests/utilities/issue/issue.go @@ -97,6 +97,10 @@ func IssuedAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Scheme, ac tx := Send(suite, version, scheme, utl.GetAccount(suite, accountNumber).PublicKey, utl.GetAccount(suite, accountNumber).SecretKey, "Asset", "Common Asset for testing", amount, utl.GetCurrentTimestampInMs(), utl.MinIssueFeeWaves, utl.MaxDecimals, true, true, nil) + if tx.WtErr.ErrWtScala != nil && tx.WtErr.ErrWtGo != nil { + suite.FailNowf("failed to issue assets", "asset: %s, ammount: %d, with errors: Scala: %s, Go: %S", + tx.TxID, amount, tx.WtErr.ErrWtScala, tx.WtErr.ErrWtGo) + } return tx.TxID } diff --git a/itests/utilities/transfer/transfer.go b/itests/utilities/transfer/transfer.go index 64846f382..f25f537cb 100644 --- a/itests/utilities/transfer/transfer.go +++ b/itests/utilities/transfer/transfer.go @@ -140,20 +140,43 @@ func BroadcastTransferTxAndGetBalances[T any](suite *f.BaseSuite, testdata testd } func TransferringFunds(suite *f.BaseSuite, version byte, scheme proto.Scheme, from, to int, - amount uint64) utl.ConsideredTransaction { + amount uint64) { sender := utl.GetAccount(suite, from) recipient := utl.GetAccount(suite, to) + + //Balances before transferring + senderBalanceGoBefore, senderBalanceScalaBefore := utl.GetAvailableBalanceInWaves(suite, sender.Address) + require.Equal(suite.T(), senderBalanceGoBefore, senderBalanceScalaBefore) + recipientBalanceGoBefore, recipientBalanceScalaBefore := utl.GetAvailableBalanceInWaves(suite, recipient.Address) + require.Equal(suite.T(), recipientBalanceGoBefore, recipientBalanceScalaBefore) + tx := Send(suite, version, scheme, sender.PublicKey, sender.SecretKey, proto.NewOptionalAssetWaves(), proto.NewOptionalAssetWaves(), utl.GetCurrentTimestampInMs(), amount, utl.MinTxFeeWaves, proto.NewRecipientFromAddress(recipient.Address), nil, true) - return tx + require.NoError(suite.T(), tx.WtErr.ErrWtGo, "Reached deadline of Transfer tx in Go") + require.NoError(suite.T(), tx.WtErr.ErrWtScala, "Reached deadline of Transfer tx in Scala") + //Waiting for changing waves balance + err := clients.Retry(utl.DefaultTimeInterval, func() error { + //Balances after transferring + senderBalanceGoAfter, senderBalanceScalaAfter := utl.GetAvailableBalanceInWaves(suite, sender.Address) + require.Equal(suite.T(), senderBalanceGoAfter, senderBalanceScalaAfter) + recipientBalanceGoAfter, recipientBalanceScalaAfter := utl.GetAvailableBalanceInWaves(suite, recipient.Address) + require.Equal(suite.T(), recipientBalanceGoAfter, recipientBalanceScalaAfter) + + if uint64(senderBalanceGoBefore-senderBalanceGoAfter) != amount && + uint64(recipientBalanceGoAfter-recipientBalanceGoBefore) != amount { + return errors.New("accounts Waves balances are mismatch") + } + + return nil + }) + require.NoError(suite.T(), err) } func GetNewAccountWithFunds(suite *f.BaseSuite, version byte, scheme proto.Scheme, from int, amount uint64) int { accNumber, _ := utl.AddNewAccount(suite, scheme) - tx := TransferringFunds(suite, version, scheme, from, accNumber, amount) - require.NoError(suite.T(), tx.WtErr.ErrWtGo, "Reached deadline of Transfer tx in Go") - require.NoError(suite.T(), tx.WtErr.ErrWtScala, "Reached deadline of Transfer tx in Scala") + TransferringFunds(suite, version, scheme, from, accNumber, amount) + // Waiting for changing waves balance. err := clients.Retry(utl.DefaultTimeInterval, func() error { balanceGo, balanceScala := utl.GetAvailableBalanceInWaves(suite, utl.GetAccount(suite, accNumber).Address) @@ -171,18 +194,44 @@ func GetNewAccountWithFunds(suite *f.BaseSuite, version byte, scheme proto.Schem func TransferringAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Scheme, assetID crypto.Digest, from, to int, assetAmount ...uint64) { var amount, currentAmount uint64 - currentAmount = uint64(utl.GetAssetBalanceGo(suite, utl.GetAccount(suite, from).Address, assetID)) + sender := utl.GetAccount(suite, from) + recipient := utl.GetAccount(suite, to) + + senderAssetBalanceGoBefore, senderAssetBalanceScalaBefore := utl.GetAssetBalance(suite, sender.Address, assetID) + require.Equal(suite.T(), senderAssetBalanceGoBefore, senderAssetBalanceScalaBefore) + recipientAssetBalanceGoBefore, recipientAssetBalanceScalaBefore := utl.GetAssetBalance(suite, recipient.Address, assetID) + require.Equal(suite.T(), recipientAssetBalanceGoBefore, recipientAssetBalanceScalaBefore) + + currentAmount = uint64(senderAssetBalanceGoBefore) if len(assetAmount) == 1 && assetAmount[0] <= currentAmount { amount = assetAmount[0] } else { amount = currentAmount } - tx := Send(suite, version, scheme, utl.GetAccount(suite, from).PublicKey, - utl.GetAccount(suite, from).SecretKey, *proto.NewOptionalAssetFromDigest(assetID), + + tx := Send(suite, version, scheme, sender.PublicKey, + sender.SecretKey, *proto.NewOptionalAssetFromDigest(assetID), proto.NewOptionalAssetWaves(), utl.GetCurrentTimestampInMs(), amount, utl.MinTxFeeWaves, - proto.NewRecipientFromAddress(utl.GetAccount(suite, to).Address), nil, true) + proto.NewRecipientFromAddress(recipient.Address), nil, true) require.NoError(suite.T(), tx.WtErr.ErrWtGo, "Reached deadline of Transfer tx in Go") require.NoError(suite.T(), tx.WtErr.ErrWtScala, "Reached deadline of Transfer tx in Scala") + //Waiting for changing waves balance + err := clients.Retry(utl.DefaultTimeInterval, func() error { + //Balances after transferring + senderAssetBalanceGoAfter, senderAssetBalanceScalaAfter := utl.GetAssetBalance(suite, sender.Address, assetID) + require.Equal(suite.T(), senderAssetBalanceGoAfter, senderAssetBalanceScalaAfter) + recipientAssetBalanceGoAfter, recipientAssetBalanceScalaAfter := utl.GetAssetBalance(suite, recipient.Address, assetID) + require.Equal(suite.T(), recipientAssetBalanceGoAfter, recipientAssetBalanceScalaAfter) + + if uint64(senderAssetBalanceGoBefore-senderAssetBalanceGoAfter) != amount && + uint64(recipientAssetBalanceGoAfter-recipientAssetBalanceGoBefore) != amount { + return errors.New("accounts asset balances are mismatch") + } + + return nil + }) + require.NoError(suite.T(), err) + } func GetVersions(suite *f.BaseSuite) []byte { From 44c8860453fd6e09e0b5529dd09ef25ec6e1794f Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Wed, 16 Oct 2024 17:58:26 +0300 Subject: [PATCH 2/7] Fix lint issues. --- itests/utilities/transfer/transfer.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/itests/utilities/transfer/transfer.go b/itests/utilities/transfer/transfer.go index f25f537cb..f0aa4dab4 100644 --- a/itests/utilities/transfer/transfer.go +++ b/itests/utilities/transfer/transfer.go @@ -144,7 +144,7 @@ func TransferringFunds(suite *f.BaseSuite, version byte, scheme proto.Scheme, fr sender := utl.GetAccount(suite, from) recipient := utl.GetAccount(suite, to) - //Balances before transferring + // Balances before transferring senderBalanceGoBefore, senderBalanceScalaBefore := utl.GetAvailableBalanceInWaves(suite, sender.Address) require.Equal(suite.T(), senderBalanceGoBefore, senderBalanceScalaBefore) recipientBalanceGoBefore, recipientBalanceScalaBefore := utl.GetAvailableBalanceInWaves(suite, recipient.Address) @@ -155,16 +155,16 @@ func TransferringFunds(suite *f.BaseSuite, version byte, scheme proto.Scheme, fr utl.MinTxFeeWaves, proto.NewRecipientFromAddress(recipient.Address), nil, true) require.NoError(suite.T(), tx.WtErr.ErrWtGo, "Reached deadline of Transfer tx in Go") require.NoError(suite.T(), tx.WtErr.ErrWtScala, "Reached deadline of Transfer tx in Scala") - //Waiting for changing waves balance + // Waiting for changing waves balance err := clients.Retry(utl.DefaultTimeInterval, func() error { - //Balances after transferring + // Balances after transferring senderBalanceGoAfter, senderBalanceScalaAfter := utl.GetAvailableBalanceInWaves(suite, sender.Address) require.Equal(suite.T(), senderBalanceGoAfter, senderBalanceScalaAfter) recipientBalanceGoAfter, recipientBalanceScalaAfter := utl.GetAvailableBalanceInWaves(suite, recipient.Address) require.Equal(suite.T(), recipientBalanceGoAfter, recipientBalanceScalaAfter) - if uint64(senderBalanceGoBefore-senderBalanceGoAfter) != amount && - uint64(recipientBalanceGoAfter-recipientBalanceGoBefore) != amount { + if uint64(utl.Abs(senderBalanceGoBefore-senderBalanceGoAfter)) != amount && + uint64(utl.Abs(recipientBalanceGoAfter-recipientBalanceGoBefore)) != amount { return errors.New("accounts Waves balances are mismatch") } @@ -199,10 +199,11 @@ func TransferringAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Sche senderAssetBalanceGoBefore, senderAssetBalanceScalaBefore := utl.GetAssetBalance(suite, sender.Address, assetID) require.Equal(suite.T(), senderAssetBalanceGoBefore, senderAssetBalanceScalaBefore) - recipientAssetBalanceGoBefore, recipientAssetBalanceScalaBefore := utl.GetAssetBalance(suite, recipient.Address, assetID) + recipientAssetBalanceGoBefore, recipientAssetBalanceScalaBefore := utl.GetAssetBalance( + suite, recipient.Address, assetID) require.Equal(suite.T(), recipientAssetBalanceGoBefore, recipientAssetBalanceScalaBefore) - currentAmount = uint64(senderAssetBalanceGoBefore) + currentAmount = uint64(utl.Abs(senderAssetBalanceGoBefore)) if len(assetAmount) == 1 && assetAmount[0] <= currentAmount { amount = assetAmount[0] } else { @@ -215,16 +216,17 @@ func TransferringAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Sche proto.NewRecipientFromAddress(recipient.Address), nil, true) require.NoError(suite.T(), tx.WtErr.ErrWtGo, "Reached deadline of Transfer tx in Go") require.NoError(suite.T(), tx.WtErr.ErrWtScala, "Reached deadline of Transfer tx in Scala") - //Waiting for changing waves balance + // Waiting for changing waves balance err := clients.Retry(utl.DefaultTimeInterval, func() error { - //Balances after transferring + // Balances after transferring senderAssetBalanceGoAfter, senderAssetBalanceScalaAfter := utl.GetAssetBalance(suite, sender.Address, assetID) require.Equal(suite.T(), senderAssetBalanceGoAfter, senderAssetBalanceScalaAfter) - recipientAssetBalanceGoAfter, recipientAssetBalanceScalaAfter := utl.GetAssetBalance(suite, recipient.Address, assetID) + recipientAssetBalanceGoAfter, recipientAssetBalanceScalaAfter := utl.GetAssetBalance( + suite, recipient.Address, assetID) require.Equal(suite.T(), recipientAssetBalanceGoAfter, recipientAssetBalanceScalaAfter) - if uint64(senderAssetBalanceGoBefore-senderAssetBalanceGoAfter) != amount && - uint64(recipientAssetBalanceGoAfter-recipientAssetBalanceGoBefore) != amount { + if uint64(utl.Abs(senderAssetBalanceGoBefore-senderAssetBalanceGoAfter)) != amount && + uint64(utl.Abs(recipientAssetBalanceGoAfter-recipientAssetBalanceGoBefore)) != amount { return errors.New("accounts asset balances are mismatch") } From 143cb4db67526e8db77660d7822a304c113b5852 Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Thu, 17 Oct 2024 14:42:04 +0300 Subject: [PATCH 3/7] Adding new method SafeInt64ToUint64. --- itests/utilities/common.go | 8 ++++++++ itests/utilities/transfer/transfer.go | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/itests/utilities/common.go b/itests/utilities/common.go index afb3477d6..5d6591561 100644 --- a/itests/utilities/common.go +++ b/itests/utilities/common.go @@ -278,6 +278,14 @@ func Abs(x int64) int64 { return x } +func SafeInt64ToUint64(x int64) uint64 { + if 0 <= x && x < math.MaxInt64 { + return uint64(x) + } else { + panic("negative number or a number greater than MaxInt64") + } +} + func SetFromToAccounts(accountNumbers ...int) (int, int, error) { var from, to int switch len(accountNumbers) { diff --git a/itests/utilities/transfer/transfer.go b/itests/utilities/transfer/transfer.go index f0aa4dab4..a80fec2e3 100644 --- a/itests/utilities/transfer/transfer.go +++ b/itests/utilities/transfer/transfer.go @@ -163,8 +163,8 @@ func TransferringFunds(suite *f.BaseSuite, version byte, scheme proto.Scheme, fr recipientBalanceGoAfter, recipientBalanceScalaAfter := utl.GetAvailableBalanceInWaves(suite, recipient.Address) require.Equal(suite.T(), recipientBalanceGoAfter, recipientBalanceScalaAfter) - if uint64(utl.Abs(senderBalanceGoBefore-senderBalanceGoAfter)) != amount && - uint64(utl.Abs(recipientBalanceGoAfter-recipientBalanceGoBefore)) != amount { + if utl.SafeInt64ToUint64(utl.Abs(senderBalanceGoBefore-senderBalanceGoAfter)) != amount && + utl.SafeInt64ToUint64(utl.Abs(recipientBalanceGoAfter-recipientBalanceGoBefore)) != amount { return errors.New("accounts Waves balances are mismatch") } @@ -203,7 +203,7 @@ func TransferringAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Sche suite, recipient.Address, assetID) require.Equal(suite.T(), recipientAssetBalanceGoBefore, recipientAssetBalanceScalaBefore) - currentAmount = uint64(utl.Abs(senderAssetBalanceGoBefore)) + currentAmount = utl.SafeInt64ToUint64(senderAssetBalanceGoBefore) if len(assetAmount) == 1 && assetAmount[0] <= currentAmount { amount = assetAmount[0] } else { @@ -225,8 +225,8 @@ func TransferringAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Sche suite, recipient.Address, assetID) require.Equal(suite.T(), recipientAssetBalanceGoAfter, recipientAssetBalanceScalaAfter) - if uint64(utl.Abs(senderAssetBalanceGoBefore-senderAssetBalanceGoAfter)) != amount && - uint64(utl.Abs(recipientAssetBalanceGoAfter-recipientAssetBalanceGoBefore)) != amount { + if utl.SafeInt64ToUint64(utl.Abs(senderAssetBalanceGoBefore-senderAssetBalanceGoAfter)) != amount && + utl.SafeInt64ToUint64(utl.Abs(recipientAssetBalanceGoAfter-recipientAssetBalanceGoBefore)) != amount { return errors.New("accounts asset balances are mismatch") } From 58162cc6a851917475c1db8da43c1e2094283099 Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Thu, 17 Oct 2024 14:57:58 +0300 Subject: [PATCH 4/7] Fix method SafeInt64ToUint64. --- itests/utilities/common.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/itests/utilities/common.go b/itests/utilities/common.go index 5d6591561..c13b355f8 100644 --- a/itests/utilities/common.go +++ b/itests/utilities/common.go @@ -279,11 +279,13 @@ func Abs(x int64) int64 { } func SafeInt64ToUint64(x int64) uint64 { - if 0 <= x && x < math.MaxInt64 { - return uint64(x) - } else { + var result uint64 + if x < 0 || x > math.MaxInt64 { panic("negative number or a number greater than MaxInt64") + } else { + result = uint64(x) } + return result } func SetFromToAccounts(accountNumbers ...int) (int, int, error) { From 02e157fa5007aba2ed667238459022adc897714a Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Thu, 17 Oct 2024 15:10:47 +0300 Subject: [PATCH 5/7] Fix method SafeInt64ToUint64. --- itests/utilities/common.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/itests/utilities/common.go b/itests/utilities/common.go index c13b355f8..67eb35f79 100644 --- a/itests/utilities/common.go +++ b/itests/utilities/common.go @@ -280,8 +280,8 @@ func Abs(x int64) int64 { func SafeInt64ToUint64(x int64) uint64 { var result uint64 - if x < 0 || x > math.MaxInt64 { - panic("negative number or a number greater than MaxInt64") + if x < 0 { + panic("negative number") } else { result = uint64(x) } From cfa530564721c35a0c5e82e7009f13b6e0f82ec1 Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Thu, 17 Oct 2024 15:18:50 +0300 Subject: [PATCH 6/7] Fix method SafeInt64ToUint64. --- itests/utilities/common.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/itests/utilities/common.go b/itests/utilities/common.go index 67eb35f79..9c7a90a54 100644 --- a/itests/utilities/common.go +++ b/itests/utilities/common.go @@ -279,13 +279,10 @@ func Abs(x int64) int64 { } func SafeInt64ToUint64(x int64) uint64 { - var result uint64 if x < 0 { panic("negative number") - } else { - result = uint64(x) } - return result + return uint64(x) } func SetFromToAccounts(accountNumbers ...int) (int, int, error) { From c00fb922aa5d3690dc580deea7df2458e6f4fbd1 Mon Sep 17 00:00:00 2001 From: irina-pereiaslavskaia Date: Fri, 18 Oct 2024 11:31:07 +0300 Subject: [PATCH 7/7] Fix method for issue assets. --- itests/utilities/issue/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itests/utilities/issue/issue.go b/itests/utilities/issue/issue.go index a12d11285..eae0e7725 100644 --- a/itests/utilities/issue/issue.go +++ b/itests/utilities/issue/issue.go @@ -97,7 +97,7 @@ func IssuedAssetAmount(suite *f.BaseSuite, version byte, scheme proto.Scheme, ac tx := Send(suite, version, scheme, utl.GetAccount(suite, accountNumber).PublicKey, utl.GetAccount(suite, accountNumber).SecretKey, "Asset", "Common Asset for testing", amount, utl.GetCurrentTimestampInMs(), utl.MinIssueFeeWaves, utl.MaxDecimals, true, true, nil) - if tx.WtErr.ErrWtScala != nil && tx.WtErr.ErrWtGo != nil { + if tx.WtErr.ErrWtScala != nil || tx.WtErr.ErrWtGo != nil { suite.FailNowf("failed to issue assets", "asset: %s, ammount: %d, with errors: Scala: %s, Go: %S", tx.TxID, amount, tx.WtErr.ErrWtScala, tx.WtErr.ErrWtGo) }