diff --git a/integrationTests/chainSimulator/common.go b/integrationTests/chainSimulator/common.go new file mode 100644 index 00000000000..0e29c33e617 --- /dev/null +++ b/integrationTests/chainSimulator/common.go @@ -0,0 +1,45 @@ +package chainSimulator + +import ( + "math/big" + + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + + "github.com/multiversx/mx-chain-core-go/data/transaction" +) + +const ( + minGasPrice = 1000000000 + txVersion = 1 + mockTxSignature = "sig" + + // OkReturnCode the const for the ok return code + OkReturnCode = "ok" +) + +var ( + // ZeroValue the variable for the zero big int + ZeroValue = big.NewInt(0) + // OneEGLD the variable for one egld value + OneEGLD = big.NewInt(1000000000000000000) + // MinimumStakeValue the variable for the minimum stake value + MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) + // InitialAmount the variable for initial minting amount in account + InitialAmount = big.NewInt(0).Mul(OneEGLD, big.NewInt(100)) +) + +// GenerateTransaction will generate a transaction based on input data +func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { + return &transaction.Transaction{ + Nonce: nonce, + Value: value, + SndAddr: sender, + RcvAddr: receiver, + Data: []byte(data), + GasLimit: gasLimit, + GasPrice: minGasPrice, + ChainID: []byte(configs.ChainID), + Version: txVersion, + Signature: []byte(mockTxSignature), + } +} diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index 759858a69c5..7aba83c5103 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -3,11 +3,12 @@ package chainSimulator import ( "math/big" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" crypto "github.com/multiversx/mx-chain-crypto-go" - "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/node/chainSimulator/process" ) // ChainSimulator defines the operations for an entity that can simulate operations of a chain @@ -16,6 +17,7 @@ type ChainSimulator interface { GenerateBlocksUntilEpochIsReached(targetEpoch int32) error AddValidatorKeys(validatorsPrivateKeys [][]byte) error GetNodeHandler(shardID uint32) process.NodeHandler + RemoveAccounts(addresses []string) error SendTxAndGenerateBlockTilTxIsExecuted(txToSend *transaction.Transaction, maxNumOfBlockToGenerateWhenExecutingTx int) (*transaction.ApiTransactionResult, error) SendTxsAndGenerateBlocksTilAreExecuted(txsToSend []*transaction.Transaction, maxNumOfBlocksToGenerateWhenExecutingTx int) ([]*transaction.ApiTransactionResult, error) SetStateMultiple(stateSlice []*dtos.AddressState) error @@ -24,4 +26,6 @@ type ChainSimulator interface { GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) ForceResetValidatorStatisticsCache() error GetValidatorPrivateKeys() []crypto.PrivateKey + SetKeyValueForAddress(address string, keyValueMap map[string]string) error + Close() } diff --git a/integrationTests/chainSimulator/staking/common.go b/integrationTests/chainSimulator/staking/common.go index a8500a05995..4de97df500e 100644 --- a/integrationTests/chainSimulator/staking/common.go +++ b/integrationTests/chainSimulator/staking/common.go @@ -5,24 +5,17 @@ import ( "math/big" "testing" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/require" ) const ( - minGasPrice = 1000000000 - txVersion = 1 - mockTxSignature = "sig" - - // OkReturnCode the const for the ok return code - OkReturnCode = "ok" // MockBLSSignature the const for a mocked bls signature MockBLSSignature = "010101" // GasLimitForStakeOperation the const for the gas limit value for the stake operation @@ -45,14 +38,8 @@ const ( ) var ( - // ZeroValue the variable for the zero big int - ZeroValue = big.NewInt(0) - // OneEGLD the variable for one egld value - OneEGLD = big.NewInt(1000000000000000000) //InitialDelegationValue the variable for the initial delegation value - InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) - // MinimumStakeValue the variable for the minimum stake value - MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) + InitialDelegationValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(1250)) ) // GetNonce will return the nonce of the provided address @@ -63,22 +50,6 @@ func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, ad return account.Nonce } -// GenerateTransaction will generate a transaction based on input data -func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - return &transaction.Transaction{ - Nonce: nonce, - Value: value, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } -} - // GetBLSKeyStatus will return the bls key status func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { scQuery := &process.SCQuery{ @@ -90,7 +61,7 @@ func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandl } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return string(result.ReturnData[0]) } @@ -105,7 +76,7 @@ func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHand } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) m := make(map[string]string) status := "" diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index b92625f0f87..3e2a1652de9 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -96,12 +97,12 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -117,7 +118,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus // do an unjail transaction unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) + txUnJail := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch) require.Nil(t, err) @@ -202,12 +203,12 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { err = cs.AddValidatorKeys([][]byte{privateKeys[1]}) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(6000)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(6000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -222,7 +223,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { // add one more node txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -234,7 +235,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { // unJail the first node unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) + txUnJail := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 198044a00e4..dcccdf5c291 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -7,18 +7,19 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/require" ) // Test scenarios @@ -87,7 +88,7 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) wallet1, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) wallet2, err := cs.GenerateAndMintWalletAddress(0, mintValue) @@ -102,15 +103,15 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus require.Nil(t, err) dataFieldTx1 := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - tx1Value := big.NewInt(0).Mul(big.NewInt(2499), staking.OneEGLD) - tx1 := staking.GenerateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, staking.GasLimitForStakeOperation) + tx1Value := big.NewInt(0).Mul(big.NewInt(2499), chainSimulatorIntegrationTests.OneEGLD) + tx1 := chainSimulatorIntegrationTests.GenerateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, staking.GasLimitForStakeOperation) dataFieldTx2 := fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - tx2 := staking.GenerateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, dataFieldTx2, staking.GasLimitForStakeOperation) + tx2 := chainSimulatorIntegrationTests.GenerateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, dataFieldTx2, staking.GasLimitForStakeOperation) dataFieldTx3 := fmt.Sprintf("stake@01@%s@%s", blsKeys[2], staking.MockBLSSignature) - tx3Value := big.NewInt(0).Mul(big.NewInt(2501), staking.OneEGLD) - tx3 := staking.GenerateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, staking.GasLimitForStakeOperation) + tx3Value := big.NewInt(0).Mul(big.NewInt(2501), chainSimulatorIntegrationTests.OneEGLD) + tx3 := chainSimulatorIntegrationTests.GenerateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, staking.GasLimitForStakeOperation) results, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx1, tx2, tx3}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -200,13 +201,13 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { err = cs.AddValidatorKeys(privateKey) require.Nil(t, err) - mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + mintValue := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) // Stake a new validator that should end up in auction in step 1 txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -226,7 +227,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { // re-stake the node txDataField = fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - txReStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, staking.GasLimitForStakeOperation) + txReStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, staking.GasLimitForStakeOperation) reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index f9a12a53036..9594ceef679 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -8,13 +8,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - coreAPI "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-core-go/data/validator" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -26,6 +19,13 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + coreAPI "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/data/validator" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/require" ) const ( @@ -354,13 +354,13 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { err = cs.AddValidatorKeys(privateKeys) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) walletAddressShardID := uint32(0) walletAddress, err := cs.GenerateAndMintWalletAddress(walletAddressShardID, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -371,7 +371,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { require.Equal(t, "staked", blsKeyStatus) // do unStake - txUnStake := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -383,13 +383,13 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { require.Nil(t, err) // do unBond - txUnBond := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) // do claim - txClaim := staking.GenerateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, "unBondTokens", staking.GasLimitForStakeOperation) + txClaim := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, "unBondTokens", staking.GasLimitForStakeOperation) claimTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txClaim, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, claimTx) @@ -401,7 +401,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { walletAccount, _, err := cs.GetNodeHandler(walletAddressShardID).GetFacadeHandler().GetAccount(walletAddress.Bech32, coreAPI.AccountQueryOptions{}) require.Nil(t, err) walletBalanceBig, _ := big.NewInt(0).SetString(walletAccount.Balance, 10) - require.True(t, walletBalanceBig.Cmp(staking.MinimumStakeValue) > 0) + require.True(t, walletBalanceBig.Cmp(chainSimulatorIntegrationTests.MinimumStakeValue) > 0) } func checkTotalQualified(t *testing.T, auctionList []*common.AuctionListValidatorAPIResponse, expected int) { @@ -592,14 +592,14 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -607,9 +607,9 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -622,9 +622,9 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul log.Info("Step 2. Create from the owner of the staked nodes a tx to stake 1 EGLD") - stakeValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(1)) + stakeValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(1)) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -640,7 +640,7 @@ func checkExpectedStakedValue(t *testing.T, metachainNode chainSimulatorProcess. totalStaked := getTotalStaked(t, metachainNode, blsKey) expectedStaked := big.NewInt(expectedValue) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(totalStaked)) } @@ -654,7 +654,7 @@ func getTotalStaked(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -828,14 +828,14 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -845,9 +845,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -863,9 +863,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -879,7 +879,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Wait for change of epoch and check the outcome") @@ -899,7 +899,7 @@ func getUnStakedTokensList(t *testing.T, metachainNode chainSimulatorProcess.Nod } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -1117,14 +1117,14 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(6000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1134,9 +1134,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1152,9 +1152,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1168,15 +1168,15 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Create from the owner of staked nodes a transaction to stake 10 EGLD and send it to the network") newStakeValue := big.NewInt(10) - newStakeValue = newStakeValue.Mul(staking.OneEGLD, newStakeValue) + newStakeValue = newStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, newStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1355,14 +1355,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1380,9 +1380,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi log.Info("Step 1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1394,7 +1394,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi testBLSKeyStaked(t, metachainNode, blsKeys[0]) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1413,10 +1413,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) // the owner balance should decrease only with the txs fee @@ -1597,14 +1597,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1620,9 +1620,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. balanceBeforeUnbonding, _ := big.NewInt(0).SetString(accountValidatorOwner.Balance, 10) unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1642,10 +1642,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) log.Info("Step 1. Wait for the unbonding epoch to start") @@ -1656,7 +1656,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. log.Info("Step 2. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1675,10 +1675,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2590) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) // the owner balance should increase with the (10 EGLD - tx fee) @@ -1876,14 +1876,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1904,9 +1904,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 2. Send the transactions in consecutive epochs, one TX in each epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1918,9 +1918,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1930,9 +1930,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1953,10 +1953,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -1968,10 +1968,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -1983,7 +1983,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2019,7 +2019,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2047,7 +2047,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2240,14 +2240,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2268,9 +2268,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 2. Send the transactions in consecutively in same epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -2278,17 +2278,17 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs unStakeTxFee, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -2305,10 +2305,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11 + 12 + 13) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -2320,10 +2320,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -2335,7 +2335,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2586,12 +2586,12 @@ func createStakeTransaction(t *testing.T, cs chainSimulatorIntegrationTests.Chai err = cs.AddValidatorKeys(privateKey) require.Nil(t, err) - mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + mintValue := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - return staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + return chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) } func unStakeOneActiveNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index bdcd9435795..bb30199e95c 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -8,17 +8,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-core-go/data/validator" - dataVm "github.com/multiversx/mx-chain-core-go/data/vm" - "github.com/multiversx/mx-chain-crypto-go/signing" - "github.com/multiversx/mx-chain-crypto-go/signing/mcl" - mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -29,6 +18,17 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/data/validator" + dataVm "github.com/multiversx/mx-chain-core-go/data/vm" + "github.com/multiversx/mx-chain-crypto-go/signing" + "github.com/multiversx/mx-chain-crypto-go/signing/mcl" + mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var log = logger.GetOrCreate("stakingProvider") @@ -291,7 +291,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 2. Set the initial state for the owner and the 2 delegators") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -306,11 +306,11 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi "newValidatorOwner", validatorOwner.Bech32, "delegator1", delegator1.Bech32, "delegator2", delegator2.Bech32) log.Info("Step 3. Do a stake transaction for the validator key and test that the new key is on queue / auction list and the correct topup") - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(500)) stakeValue.Add(stakeValue, addedStakedValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -322,7 +322,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue / auction list and the correct topup") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + txConvert := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForConvertOperation) convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -337,35 +337,35 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700") - delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) - txDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) + txDelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - txDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + txDelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(700)) + expectedTopUp := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(700)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) log.Info("6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500") - unDelegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + unDelegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + txUnDelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 1, delegationAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForDelegate) unDelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate1Tx) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + txUnDelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 1, delegationAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForDelegate) unDelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate2Tx) - expectedTopUp = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) + expectedTopUp = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(500)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) } @@ -635,7 +635,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 2. Set the initial state for 2 owners") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwnerA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -648,12 +648,12 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 3. Do 2 stake transactions and test that the new keys are on queue / auction list and have the correct topup") - topupA := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) - stakeValueA := big.NewInt(0).Add(staking.MinimumStakeValue, topupA) + topupA := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) + stakeValueA := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, topupA) txStakeA := generateStakeTransaction(t, cs, validatorOwnerA, blsKeys[0], stakeValueA) - topupB := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) - stakeValueB := big.NewInt(0).Add(staking.MinimumStakeValue, topupB) + topupB := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(200)) + stakeValueB := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, topupB) txStakeB := generateStakeTransaction(t, cs, validatorOwnerB, blsKeys[1], stakeValueB) stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeA, txStakeB}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -884,7 +884,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 2. Set the initial state for 1 owner and 1 delegator") mintValue := big.NewInt(10001) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) owner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -897,8 +897,8 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 3. Do a stake transaction and test that the new key is on queue / auction list and has the correct topup") - topup := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(99)) - stakeValue := big.NewInt(0).Add(staking.MinimumStakeValue, topup) + topup := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(99)) + stakeValue := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, topup) txStake := generateStakeTransaction(t, cs, owner, blsKeys[0], stakeValue) stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStake}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -928,17 +928,17 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 5. Add 2 nodes in the staking contract") txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s@%s@%s", blsKeys[1], staking.MockBLSSignature+"02", blsKeys[2], staking.MockBLSSignature+"03") ownerNonce := staking.GetNonce(t, cs, owner) - txAddNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) addNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txAddNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(addNodesTxs)) log.Info("Step 6. Delegate 5000 EGLD to the contract") - delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(5000)) + delegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(5000)) txDataFieldDelegate := "delegate" delegatorNonce := staking.GetNonce(t, cs, delegator) - txDelegate := staking.GenerateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, staking.GasLimitForStakeOperation) + txDelegate := chainSimulatorIntegrationTests.GenerateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, staking.GasLimitForStakeOperation) delegateTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txDelegate}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -947,7 +947,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 7. Stake the 2 nodes") txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s@%s", blsKeys[1], blsKeys[2]) ownerNonce = staking.GetNonce(t, cs, owner) - txStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -963,7 +963,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta txDataFieldUnStakeNodes := fmt.Sprintf("unStakeNodes@%s@%s", blsKeys[1], blsKeys[2]) ownerNonce = staking.GetNonce(t, cs, owner) - txUnStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, staking.GasLimitForStakeOperation) + txUnStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, staking.GasLimitForStakeOperation) unStakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -981,7 +981,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta txDataFieldUnBondNodes := fmt.Sprintf("unBondNodes@%s@%s", blsKeys[1], blsKeys[2]) ownerNonce = staking.GetNonce(t, cs, owner) - txUnBondNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, staking.GasLimitForStakeOperation) + txUnBondNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, staking.GasLimitForStakeOperation) unBondNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnBondNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1010,7 +1010,7 @@ func generateStakeTransaction( require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeyHex, staking.MockBLSSignature) - return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + return chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) } func generateConvertToStakingProviderTransaction( @@ -1022,7 +1022,7 @@ func generateConvertToStakingProviderTransaction( require.Nil(t, err) txDataField := fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + return chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForConvertOperation) } // Test description @@ -1218,7 +1218,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - initialFunds := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each + initialFunds := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) @@ -1228,8 +1228,8 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) - maxDelegationCap := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap - txCreateDelegationContract := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, + maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap + txCreateDelegationContract := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -1261,7 +1261,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) signatures := getSignatures(delegationContractAddressBytes, validatorSecretKeysBytes) - txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) @@ -1286,7 +1286,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - txDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + txDelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) @@ -1302,7 +1302,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - txDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + txDelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) @@ -1320,7 +1320,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // Step 4: Perform stakeNodes - txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) @@ -1347,7 +1347,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the staked state // The total active stake should be reduced by the amount undelegated - txUndelegate1 := staking.GenerateTransaction(delegator1.Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 1, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate1Tx) @@ -1361,7 +1361,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) - require.Equal(t, staking.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) @@ -1375,7 +1375,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should change to unStaked state // The total active stake should be reduced by the amount undelegated - txUndelegate2 := staking.GenerateTransaction(delegator2.Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 1, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate2Tx) @@ -1383,7 +1383,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, "1250000000000000000000", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) - require.Equal(t, staking.ZeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2.Bytes}) require.Nil(t, err) @@ -1600,7 +1600,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - initialFunds := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each + initialFunds := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) @@ -1615,8 +1615,8 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati // Step 3: Create a new delegation contract - maxDelegationCap := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) // 3000 EGLD cap - txCreateDelegationContract := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, + maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) // 3000 EGLD cap + txCreateDelegationContract := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -1636,7 +1636,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) signatures := getSignatures(delegationContractAddress, validatorSecretKeysBytes) - txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddress, staking.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddress, chainSimulatorIntegrationTests.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) @@ -1653,7 +1653,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - tx1delegatorA := staking.GenerateTransaction(delegatorA.Bytes, 0, delegationContractAddress, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + tx1delegatorA := chainSimulatorIntegrationTests.GenerateTransaction(delegatorA.Bytes, 0, delegationContractAddress, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) delegatorATx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorA, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorATx1) @@ -1669,8 +1669,8 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(501)) // 501 EGLD - tx1delegatorB := staking.GenerateTransaction(delegatorB.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(501)) // 501 EGLD + tx1delegatorB := chainSimulatorIntegrationTests.GenerateTransaction(delegatorB.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorB, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx1) @@ -1688,12 +1688,12 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati // Step 4: Perform stakeNodes - txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddress, staking.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddress, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - require.Equal(t, staking.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) require.Nil(t, err) @@ -1706,9 +1706,9 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], staking.ZeroValue, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], chainSimulatorIntegrationTests.ZeroValue, 1) - tx2delegatorB := staking.GenerateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + tx2delegatorB := chainSimulatorIntegrationTests.GenerateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx2) @@ -1719,15 +1719,15 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Equal(t, staking.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) - delegateValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) // 500 EGLD - tx3delegatorB := staking.GenerateTransaction(delegatorB.Bytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(500)) // 500 EGLD + tx3delegatorB := chainSimulatorIntegrationTests.GenerateTransaction(delegatorB.Bytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx3, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx3delegatorB, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx3) @@ -1743,8 +1743,8 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.Equal(t, delegateValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - delegateValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(20)) // 20 EGLD - tx1DelegatorC := staking.GenerateTransaction(delegatorC.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(20)) // 20 EGLD + tx1DelegatorC := chainSimulatorIntegrationTests.GenerateTransaction(delegatorC.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1DelegatorC, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorCTx1) @@ -1818,7 +1818,7 @@ func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHand } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) if len(result.ReturnData[0]) == 0 { return big.NewInt(0) @@ -1998,7 +1998,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(3000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -2007,11 +2007,11 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat require.Nil(t, err) log.Info("Step 1. User A: - stake 1 node to have 100 egld more than minimum stake value") - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2024,7 +2024,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 2. Execute MakeNewContractFromValidatorData for User A") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := staking.GenerateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + txConvert := chainSimulatorIntegrationTests.GenerateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForConvertOperation) convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -2037,11 +2037,11 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 3. User B: - stake 1 node to have 100 egld more") - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) - addedStakedValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) + addedStakedValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2060,7 +2060,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 4. User A : whitelistForMerge@addressB") txDataField = fmt.Sprintf("whitelistForMerge@%s", hex.EncodeToString(validatorB.Bytes)) - whitelistForMerge := staking.GenerateTransaction(validatorA.Bytes, 2, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + whitelistForMerge := chainSimulatorIntegrationTests.GenerateTransaction(validatorA.Bytes, 2, delegationAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForDelegate) whitelistForMergeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(whitelistForMerge, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, whitelistForMergeTx) @@ -2071,7 +2071,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 5. User A : mergeValidatorToDelegationWithWhitelist") txDataField = fmt.Sprintf("mergeValidatorToDelegationWithWhitelist@%s", hex.EncodeToString(delegationAddress)) - txConvert = staking.GenerateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForMergeOperation) + txConvert = chainSimulatorIntegrationTests.GenerateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForMergeOperation) convertTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -2085,7 +2085,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat decodedBLSKey1, _ = hex.DecodeString(blsKeys[1]) require.Equal(t, delegationAddress, getBLSKeyOwner(t, metachainNode, decodedBLSKey1)) - expectedTopUpValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) + expectedTopUpValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(200)) require.Equal(t, expectedTopUpValue, getBLSTopUpValue(t, metachainNode, delegationAddress)) } @@ -2099,7 +2099,7 @@ func getBLSKeyOwner(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 649f807e6ce..05b3f1b8eac 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/multiversx/mx-chain-go/config" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -73,7 +74,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(big.NewInt(5000), staking.OneEGLD) + mintValue := big.NewInt(0).Mul(big.NewInt(5000), chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) require.Nil(t, err) @@ -84,7 +85,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati // create delegation contract stakeValue, _ := big.NewInt(0).SetString("4250000000000000000000", 10) dataField := "createNewDelegationContract@00@0ea1" - txStake := staking.GenerateTransaction(validatorOwner.Bytes, staking.GetNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, staking.GetNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -98,14 +99,14 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], staking.MockBLSSignature+"02") ownerNonce := staking.GetNonce(t, cs, validatorOwner) - txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s", blsKeys[0]) ownerNonce = staking.GetNonce(t, cs, validatorOwner) - txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -129,7 +130,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati ownerNonce = staking.GetNonce(t, cs, validatorOwner) reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - reStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, staking.GasLimitForStakeOperation) + reStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, staking.GasLimitForStakeOperation) reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) diff --git a/integrationTests/chainSimulator/testing.go b/integrationTests/chainSimulator/testing.go new file mode 100644 index 00000000000..605bf76ac7f --- /dev/null +++ b/integrationTests/chainSimulator/testing.go @@ -0,0 +1,245 @@ +package chainSimulator + +import ( + "encoding/base64" + "math/big" + "testing" + "time" + + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/node/chainSimulator/errors" + chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-go/process" + + "github.com/multiversx/mx-chain-core-go/core" + coreAPI "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// CheckSetState - +func CheckSetState(t *testing.T, chainSimulator ChainSimulator, nodeHandler chainSimulatorProcess.NodeHandler) { + keyValueMap := map[string]string{ + "01": "01", + "02": "02", + } + + address := "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj" + err := chainSimulator.SetKeyValueForAddress(address, keyValueMap) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(1) + require.Nil(t, err) + + keyValuePairs, _, err := nodeHandler.GetFacadeHandler().GetKeyValuePairs(address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, keyValueMap, keyValuePairs) +} + +// CheckSetEntireState - +func CheckSetEntireState(t *testing.T, chainSimulator ChainSimulator, nodeHandler chainSimulatorProcess.NodeHandler, accountState *dtos.AddressState) { + err := chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(30) + require.Nil(t, err) + + scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(accountState.Address) + res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: nil, + BlockNonce: core.OptionalUint64{}, + }) + require.Nil(t, err) + + counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() + require.Equal(t, 10, int(counterValue)) + + time.Sleep(time.Second) + + account, _, err := nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) +} + +// CheckSetEntireStateWithRemoval - +func CheckSetEntireStateWithRemoval(t *testing.T, chainSimulator ChainSimulator, nodeHandler chainSimulatorProcess.NodeHandler, accountState *dtos.AddressState) { + // activate the auto balancing tries so the results will be the same + err := chainSimulator.GenerateBlocks(30) + require.Nil(t, err) + + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(accountState.Address) + res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: nil, + BlockNonce: core.OptionalUint64{}, + }) + require.Nil(t, err) + + counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() + require.Equal(t, 10, int(counterValue)) + + account, _, err := nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + + // Now we remove the account + err = chainSimulator.RemoveAccounts([]string{accountState.Address}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, "0", account.Balance) + require.Equal(t, "0", account.DeveloperReward) + require.Equal(t, "", account.Code) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, "", account.OwnerAddress) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.RootHash)) + + // Set the state again + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) +} + +// CheckGetAccount - +func CheckGetAccount(t *testing.T, chainSimulator ChainSimulator) { + // the facade's GetAccount method requires that at least one block was produced over the genesis block + err := chainSimulator.GenerateBlocks(1) + require.Nil(t, err) + + address := dtos.WalletAddress{ + Bech32: "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj", + } + address.Bytes, err = chainSimulator.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(address.Bech32) + require.Nil(t, err) + + account, err := chainSimulator.GetAccount(address) + require.Nil(t, err) + require.Equal(t, uint64(0), account.Nonce) + require.Equal(t, "0", account.Balance) + + nonce := uint64(37) + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{ + { + Address: address.Bech32, + Nonce: &nonce, + Balance: big.NewInt(38).String(), + }, + }) + require.Nil(t, err) + + // without this call the test will fail because the latest produced block points to a state roothash that tells that + // the account has the nonce 0 + _ = chainSimulator.GenerateBlocks(1) + + account, err = chainSimulator.GetAccount(address) + require.Nil(t, err) + require.Equal(t, uint64(37), account.Nonce) + require.Equal(t, "38", account.Balance) +} + +// CheckGenerateTransactions - +func CheckGenerateTransactions(t *testing.T, chainSimulator ChainSimulator) { + transferValue := big.NewInt(0).Mul(OneEGLD, big.NewInt(5)) + + wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, InitialAmount) + require.Nil(t, err) + + wallet1, err := chainSimulator.GenerateAndMintWalletAddress(1, InitialAmount) + require.Nil(t, err) + + wallet2, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) + require.Nil(t, err) + + wallet3, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) + require.Nil(t, err) + + wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) + require.Nil(t, err) + + gasLimit := uint64(50000) + tx0 := GenerateTransaction(wallet0.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) + tx1 := GenerateTransaction(wallet1.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) + tx3 := GenerateTransaction(wallet3.Bytes, 0, wallet4.Bytes, transferValue, "", gasLimit) + + maxNumOfBlockToGenerateWhenExecutingTx := 15 + + t.Run("nil or empty slice of transactions should error", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(nil, 1) + assert.Equal(t, errors.ErrEmptySliceOfTxs, errSend) + assert.Nil(t, sentTxs) + + sentTxs, errSend = chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(make([]*transaction.Transaction, 0), 1) + assert.Equal(t, errors.ErrEmptySliceOfTxs, errSend) + assert.Nil(t, sentTxs) + }) + t.Run("invalid max number of blocks to generate should error", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, 0) + assert.Equal(t, errors.ErrInvalidMaxNumOfBlocks, errSend) + assert.Nil(t, sentTxs) + }) + t.Run("nil transaction in slice should error", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{nil}, 1) + assert.ErrorIs(t, errSend, errors.ErrNilTransaction) + assert.Nil(t, sentTxs) + }) + t.Run("2 transactions from different shard should call send correctly", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, maxNumOfBlockToGenerateWhenExecutingTx) + assert.Equal(t, 2, len(sentTxs)) + assert.Nil(t, errSend) + + account, errGet := chainSimulator.GetAccount(wallet2) + assert.Nil(t, errGet) + expectedBalance := big.NewInt(0).Add(InitialAmount, transferValue) + expectedBalance.Add(expectedBalance, transferValue) + assert.Equal(t, expectedBalance.String(), account.Balance) + }) + t.Run("1 transaction should be sent correctly", func(t *testing.T) { + _, errSend := chainSimulator.SendTxAndGenerateBlockTilTxIsExecuted(tx3, maxNumOfBlockToGenerateWhenExecutingTx) + assert.Nil(t, errSend) + + account, errGet := chainSimulator.GetAccount(wallet4) + assert.Nil(t, errGet) + expectedBalance := big.NewInt(0).Add(InitialAmount, transferValue) + assert.Equal(t, expectedBalance.String(), account.Balance) + }) +} diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index aa2c6aa5453..e8ebd406739 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -14,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + chainSimulatorErrors "github.com/multiversx/mx-chain-go/node/chainSimulator/errors" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" mxChainSharding "github.com/multiversx/mx-chain-go/sharding" @@ -516,16 +517,16 @@ func (s *simulator) SendTxAndGenerateBlockTilTxIsExecuted(txToSend *transaction. // SendTxsAndGenerateBlocksTilAreExecuted will send the provided transactions and generate block until all transactions are executed func (s *simulator) SendTxsAndGenerateBlocksTilAreExecuted(txsToSend []*transaction.Transaction, maxNumOfBlocksToGenerateWhenExecutingTx int) ([]*transaction.ApiTransactionResult, error) { if len(txsToSend) == 0 { - return nil, errEmptySliceOfTxs + return nil, chainSimulatorErrors.ErrEmptySliceOfTxs } if maxNumOfBlocksToGenerateWhenExecutingTx == 0 { - return nil, errInvalidMaxNumOfBlocks + return nil, chainSimulatorErrors.ErrInvalidMaxNumOfBlocks } transactionStatus := make([]*transactionWithResult, 0, len(txsToSend)) for idx, tx := range txsToSend { if tx == nil { - return nil, fmt.Errorf("%w on position %d", errNilTransaction, idx) + return nil, fmt.Errorf("%w on position %d", chainSimulatorErrors.ErrNilTransaction, idx) } txHashHex, err := s.sendTx(tx) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 992c56626af..190cf5a62b0 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -1,20 +1,16 @@ package chainSimulator import ( - "encoding/base64" "math/big" "testing" "time" "github.com/multiversx/mx-chain-go/config" + chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-core-go/core" - coreAPI "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -232,22 +228,7 @@ func TestChainSimulator_SetState(t *testing.T) { defer chainSimulator.Close() - keyValueMap := map[string]string{ - "01": "01", - "02": "02", - } - - address := "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj" - err = chainSimulator.SetKeyValueForAddress(address, keyValueMap) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(1) - require.Nil(t, err) - - nodeHandler := chainSimulator.GetNodeHandler(0) - keyValuePairs, _, err := nodeHandler.GetFacadeHandler().GetKeyValuePairs(address, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, keyValueMap, keyValuePairs) + chainSimulatorCommon.CheckSetState(t, chainSimulator, chainSimulator.GetNodeHandler(0)) } func TestChainSimulator_SetEntireState(t *testing.T) { @@ -297,36 +278,7 @@ func TestChainSimulator_SetEntireState(t *testing.T) { }, } - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(30) - require.Nil(t, err) - - nodeHandler := chainSimulator.GetNodeHandler(1) - scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(contractAddress) - res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ - ScAddress: scAddress, - FuncName: "getSum", - CallerAddr: nil, - BlockNonce: core.OptionalUint64{}, - }) - require.Nil(t, err) - - counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() - require.Equal(t, 10, int(counterValue)) - - time.Sleep(time.Second) - - account, _, err := nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, accountState.Balance, account.Balance) - require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) - require.Equal(t, accountState.Code, account.Code) - require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, accountState.Owner, account.OwnerAddress) - require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + chainSimulatorCommon.CheckSetEntireState(t, chainSimulator, chainSimulator.GetNodeHandler(1), accountState) } func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { @@ -359,10 +311,6 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { defer chainSimulator.Close() - // activate the auto balancing tries so the results will be the same - err = chainSimulator.GenerateBlocks(30) - require.Nil(t, err) - balance := "431271308732096033771131" contractAddress := "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5" accountState := &dtos.AddressState{ @@ -379,70 +327,7 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { "73756d": "0a", }, } - - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(2) - require.Nil(t, err) - - nodeHandler := chainSimulator.GetNodeHandler(1) - scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(contractAddress) - res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ - ScAddress: scAddress, - FuncName: "getSum", - CallerAddr: nil, - BlockNonce: core.OptionalUint64{}, - }) - require.Nil(t, err) - - counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() - require.Equal(t, 10, int(counterValue)) - - account, _, err := nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, accountState.Balance, account.Balance) - require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) - require.Equal(t, accountState.Code, account.Code) - require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, accountState.Owner, account.OwnerAddress) - require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) - - // Now we remove the account - err = chainSimulator.RemoveAccounts([]string{contractAddress}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(2) - require.Nil(t, err) - - account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, "0", account.Balance) - require.Equal(t, "0", account.DeveloperReward) - require.Equal(t, "", account.Code) - require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, "", account.OwnerAddress) - require.Equal(t, "", base64.StdEncoding.EncodeToString(account.RootHash)) - - // Set the state again - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(2) - require.Nil(t, err) - - account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - - require.Equal(t, accountState.Balance, account.Balance) - require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) - require.Equal(t, accountState.Code, account.Code) - require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, accountState.Owner, account.OwnerAddress) - require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + chainSimulatorCommon.CheckSetEntireStateWithRemoval(t, chainSimulator, chainSimulator.GetNodeHandler(1), accountState) } func TestChainSimulator_GetAccount(t *testing.T) { @@ -478,35 +363,7 @@ func TestChainSimulator_GetAccount(t *testing.T) { defer chainSimulator.Close() - address := dtos.WalletAddress{ - Bech32: "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj", - } - address.Bytes, err = chainSimulator.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(address.Bech32) - assert.Nil(t, err) - - account, err := chainSimulator.GetAccount(address) - assert.Nil(t, err) - assert.Equal(t, uint64(0), account.Nonce) - assert.Equal(t, "0", account.Balance) - - nonce := uint64(37) - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{ - { - Address: address.Bech32, - Nonce: &nonce, - Balance: big.NewInt(38).String(), - }, - }) - assert.Nil(t, err) - - // without this call the test will fail because the latest produced block points to a state roothash that tells that - // the account has the nonce 0 - _ = chainSimulator.GenerateBlocks(1) - - account, err = chainSimulator.GetAccount(address) - assert.Nil(t, err) - assert.Equal(t, uint64(37), account.Nonce) - assert.Equal(t, "38", account.Balance) + chainSimulatorCommon.CheckGetAccount(t, chainSimulator) } func TestSimulator_SendTransactions(t *testing.T) { @@ -539,89 +396,5 @@ func TestSimulator_SendTransactions(t *testing.T) { defer chainSimulator.Close() - oneEgld := big.NewInt(1000000000000000000) - initialMinting := big.NewInt(0).Mul(oneEgld, big.NewInt(100)) - transferValue := big.NewInt(0).Mul(oneEgld, big.NewInt(5)) - - wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, initialMinting) - require.Nil(t, err) - - wallet1, err := chainSimulator.GenerateAndMintWalletAddress(1, initialMinting) - require.Nil(t, err) - - wallet2, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) - require.Nil(t, err) - - wallet3, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) - require.Nil(t, err) - - wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) - require.Nil(t, err) - - gasLimit := uint64(50000) - tx0 := generateTransaction(wallet0.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) - tx1 := generateTransaction(wallet1.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) - tx3 := generateTransaction(wallet3.Bytes, 0, wallet4.Bytes, transferValue, "", gasLimit) - - maxNumOfBlockToGenerateWhenExecutingTx := 15 - - t.Run("nil or empty slice of transactions should error", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(nil, 1) - assert.Equal(t, errEmptySliceOfTxs, errSend) - assert.Nil(t, sentTxs) - - sentTxs, errSend = chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(make([]*transaction.Transaction, 0), 1) - assert.Equal(t, errEmptySliceOfTxs, errSend) - assert.Nil(t, sentTxs) - }) - t.Run("invalid max number of blocks to generate should error", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, 0) - assert.Equal(t, errInvalidMaxNumOfBlocks, errSend) - assert.Nil(t, sentTxs) - }) - t.Run("nil transaction in slice should error", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{nil}, 1) - assert.ErrorIs(t, errSend, errNilTransaction) - assert.Nil(t, sentTxs) - }) - t.Run("2 transactions from different shard should call send correctly", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, maxNumOfBlockToGenerateWhenExecutingTx) - assert.Equal(t, 2, len(sentTxs)) - assert.Nil(t, errSend) - - account, errGet := chainSimulator.GetAccount(wallet2) - assert.Nil(t, errGet) - expectedBalance := big.NewInt(0).Add(initialMinting, transferValue) - expectedBalance.Add(expectedBalance, transferValue) - assert.Equal(t, expectedBalance.String(), account.Balance) - }) - t.Run("1 transaction should be sent correctly", func(t *testing.T) { - _, errSend := chainSimulator.SendTxAndGenerateBlockTilTxIsExecuted(tx3, maxNumOfBlockToGenerateWhenExecutingTx) - assert.Nil(t, errSend) - - account, errGet := chainSimulator.GetAccount(wallet4) - assert.Nil(t, errGet) - expectedBalance := big.NewInt(0).Add(initialMinting, transferValue) - assert.Equal(t, expectedBalance.String(), account.Balance) - }) -} - -func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - minGasPrice := uint64(1000000000) - txVersion := uint32(1) - mockTxSignature := "sig" - - transferValue := big.NewInt(0).Set(value) - return &transaction.Transaction{ - Nonce: nonce, - Value: transferValue, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } + chainSimulatorCommon.CheckGenerateTransactions(t, chainSimulator) } diff --git a/node/chainSimulator/errors.go b/node/chainSimulator/errors.go index 5e2dec0c16a..57f0db0c457 100644 --- a/node/chainSimulator/errors.go +++ b/node/chainSimulator/errors.go @@ -3,10 +3,7 @@ package chainSimulator import "errors" var ( - errNilChainSimulator = errors.New("nil chain simulator") - errNilMetachainNode = errors.New("nil metachain node") - errShardSetupError = errors.New("shard setup error") - errEmptySliceOfTxs = errors.New("empty slice of transactions to send") - errNilTransaction = errors.New("nil transaction") - errInvalidMaxNumOfBlocks = errors.New("invalid max number of blocks to generate") + errNilChainSimulator = errors.New("nil chain simulator") + errNilMetachainNode = errors.New("nil metachain node") + errShardSetupError = errors.New("shard setup error") ) diff --git a/node/chainSimulator/errors/errors.go b/node/chainSimulator/errors/errors.go new file mode 100644 index 00000000000..c1be2d016b1 --- /dev/null +++ b/node/chainSimulator/errors/errors.go @@ -0,0 +1,12 @@ +package errors + +import "errors" + +// ErrEmptySliceOfTxs signals that an empty slice of transactions has been provided +var ErrEmptySliceOfTxs = errors.New("empty slice of transactions to send") + +// ErrNilTransaction signals that a nil transaction has been provided +var ErrNilTransaction = errors.New("nil transaction") + +// ErrInvalidMaxNumOfBlocks signals that an invalid max numerof blocks has been provided +var ErrInvalidMaxNumOfBlocks = errors.New("invalid max number of blocks to generate")