Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an error occurrence in case of a problem with the issue of assets and checks in transfer methods. #1516

Merged
merged 11 commits into from
Oct 18, 2024
Merged
7 changes: 7 additions & 0 deletions itests/utilities/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ func Abs(x int64) int64 {
return x
}

func SafeInt64ToUint64(x int64) uint64 {
if x < 0 {
panic("negative number")
}
return uint64(x)
}

func SetFromToAccounts(accountNumbers ...int) (int, int, error) {
var from, to int
switch len(accountNumbers) {
Expand Down
4 changes: 4 additions & 0 deletions itests/utilities/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
69 changes: 60 additions & 9 deletions itests/utilities/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 utl.SafeInt64ToUint64(utl.Abs(senderBalanceGoBefore-senderBalanceGoAfter)) != amount &&
utl.SafeInt64ToUint64(utl.Abs(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)
Expand All @@ -171,18 +194,46 @@ 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 = utl.SafeInt64ToUint64(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 utl.SafeInt64ToUint64(utl.Abs(senderAssetBalanceGoBefore-senderAssetBalanceGoAfter)) != amount &&
utl.SafeInt64ToUint64(utl.Abs(recipientAssetBalanceGoAfter-recipientAssetBalanceGoBefore)) != amount {
return errors.New("accounts asset balances are mismatch")
}

return nil
})
require.NoError(suite.T(), err)

}

func GetVersions(suite *f.BaseSuite) []byte {
Expand Down
Loading