Skip to content

Commit

Permalink
Merge pull request #6330 from multiversx/refactor-white-list-data-ver…
Browse files Browse the repository at this point in the history
…ifier-chain-simulator

White list data verifier fixes chain simulator
  • Loading branch information
miiu96 authored Jul 31, 2024
2 parents b6f3e88 + 1eefd6f commit a369185
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 22 deletions.
15 changes: 15 additions & 0 deletions integrationTests/chainSimulator/relayedTx/relayedTx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.
receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0))
require.NoError(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit)
innerTx.RelayerAddr = relayer.Bytes

Expand All @@ -71,6 +74,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.
receiver2, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0))
require.NoError(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit)
innerTx2.RelayerAddr = relayer.Bytes

Expand All @@ -81,6 +87,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.
owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
require.NoError(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

scCode := wasm.GetSCCode("testData/egld-esdt-swap.wasm")
params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, hex.EncodeToString([]byte("WEGLD"))}
txDataDeploy := strings.Join(params, "@")
Expand Down Expand Up @@ -164,6 +173,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t
owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
require.NoError(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

ownerNonce := uint64(0)
scCode := wasm.GetSCCode("testData/adder.wasm")
params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"}
Expand Down Expand Up @@ -465,6 +477,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerNotExec
guardian, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
require.NoError(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

// Set guardian for sender
senderNonce := uint64(0)
setGuardianTxData := "SetGuardian@" + hex.EncodeToString(guardian.Bytes) + "@" + hex.EncodeToString([]byte("uuid"))
Expand Down
6 changes: 6 additions & 0 deletions integrationTests/chainSimulator/staking/jail/jail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus
walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation)
stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx)
Expand Down Expand Up @@ -203,6 +206,9 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) {
walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation)
stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus
wallet3, err := cs.GenerateAndMintWalletAddress(0, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

_, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(3)
require.Nil(t, err)

Expand Down Expand Up @@ -201,6 +204,9 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) {
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
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 := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) {
})
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

// Step 3 --- generate and send a stake transaction with the BLS key of the validator key that was added at step 1
stakeValue, _ := big.NewInt(0).SetString("2500000000000000000000", 10)
tx := &transaction.Transaction{
Expand Down Expand Up @@ -237,6 +240,9 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) {
})
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

// Step 3 --- generate and send a stake transaction with the BLS keys of the validators key that were added at step 1
validatorData := ""
for _, blsKey := range blsKeys {
Expand Down Expand Up @@ -353,6 +359,9 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) {
walletAddress, err := cs.GenerateAndMintWalletAddress(walletAddressShardID, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation)
stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx)
Expand Down Expand Up @@ -583,6 +592,9 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue)
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -811,6 +823,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue)
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -1092,6 +1107,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue)
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -1322,6 +1340,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600))
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -1556,6 +1577,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing.
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600))
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -1827,6 +1851,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T,
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600))
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -2183,6 +2210,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600))
txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation)
Expand Down Expand Up @@ -2524,6 +2554,9 @@ func createStakeTransaction(t *testing.T, cs chainSimulatorIntegrationTests.Chai
validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature)
return chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi
delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

log.Info("working with the following addresses",
"newValidatorOwner", validatorOwner.Bech32, "delegator1", delegator1.Bech32, "delegator2", delegator2.Bech32)

Expand Down Expand Up @@ -625,6 +628,9 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t *
validatorOwnerB, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

log.Info("working with the following addresses",
"validatorOwnerA", validatorOwnerA.Bech32, "validatorOwnerB", validatorOwnerB.Bech32)

Expand Down Expand Up @@ -866,6 +872,9 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta
delegator, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

log.Info("working with the following addresses",
"owner", owner.Bech32, "", delegator.Bech32)

Expand Down Expand Up @@ -1194,6 +1203,9 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat
delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

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),
Expand Down Expand Up @@ -1571,6 +1583,9 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati
delegatorC, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

// Step 3: Create a new delegation contract

maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) // 3000 EGLD cap
Expand Down Expand Up @@ -1956,6 +1971,9 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat
validatorB, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
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(chainSimulatorIntegrationTests.MinimumStakeValue)
addedStakedValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati
mintValue := big.NewInt(0).Mul(big.NewInt(5000), chainSimulatorIntegrationTests.OneEGLD)
validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

err = cs.GenerateBlocksUntilEpochIsReached(1)
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/chainSimulator/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func CheckGenerateTransactions(t *testing.T, chainSimulator ChainSimulator) {
wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount)
require.Nil(t, err)

err = chainSimulator.GenerateBlocks(1)
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)
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/chainSimulator/vm/esdtImprovements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ func createAddresses(
address3, err := cs.GenerateAndMintWalletAddress(shardIDs[2], mintValue)
require.Nil(t, err)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

return []dtos.WalletAddress{address, address2, address3}
}

Expand Down
54 changes: 52 additions & 2 deletions node/chainSimulator/chainSimulator_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package chainSimulator

import (
"github.com/multiversx/mx-chain-go/errors"
"math/big"
"strings"
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"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-core-go/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -380,3 +383,50 @@ func TestSimulator_SendTransactions(t *testing.T) {

chainSimulatorCommon.CheckGenerateTransactions(t, chainSimulator)
}

func TestSimulator_SentMoveBalanceNoGasForFee(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}

startTime := time.Now().Unix()
roundDurationInMillis := uint64(6000)
roundsPerEpoch := core.OptionalUint64{
HasValue: true,
Value: 20,
}
chainSimulator, err := NewChainSimulator(ArgsChainSimulator{
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
NumOfShards: 3,
GenesisTimestamp: startTime,
RoundDurationInMillis: roundDurationInMillis,
RoundsPerEpoch: roundsPerEpoch,
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 1,
MetaChainMinNodes: 1,
})
require.Nil(t, err)
require.NotNil(t, chainSimulator)

defer chainSimulator.Close()

wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, big.NewInt(0))
require.Nil(t, err)

ftx := &transaction.Transaction{
Nonce: 0,
Value: big.NewInt(0),
SndAddr: wallet0.Bytes,
RcvAddr: wallet0.Bytes,
Data: []byte(""),
GasLimit: 50_000,
GasPrice: 1_000_000_000,
ChainID: []byte(configs.ChainID),
Version: 1,
Signature: []byte("010101"),
}
_, err = chainSimulator.sendTx(ftx)
require.True(t, strings.Contains(err.Error(), errors.ErrInsufficientFunds.Error()))
}
Loading

0 comments on commit a369185

Please sign in to comment.