Skip to content

Commit

Permalink
Merge pull request #6596 from multiversx/MX-16051-chain-sim-tests-ref…
Browse files Browse the repository at this point in the history
…actor

Refactor register functions to be usable in sovereign chain simulator
  • Loading branch information
axenteoctavian authored Nov 12, 2024
2 parents eaae00c + 691b005 commit 139e848
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions integrationTests/chainSimulator/bridge/esdtSafe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestChainSimulator_ExecuteAndDepositTokensWithPrefix(t *testing.T) {
// register sovereign token identifier
// this will issue a new token on main chain and create a mapper between the identifiers
registerTokens(t, cs, wallet, &nonce, bridgeData.ESDTSafeAddress, token)
tokensMapper[token.Identifier] = chainSim.GetIssuedEsdtIdentifier(t, cs.GetNodeHandler(core.MetachainShardId), getTokenTicker(token.Identifier), token.Type.String())
tokensMapper[token.Identifier] = chainSim.GetIssuedEsdtIdentifier(t, cs, getTokenTicker(token.Identifier), token.Type.String())

// create random receiver addresses in a shard
receiver, _ := cs.GenerateAndMintWalletAddress(receiverShardId, chainSim.InitialAmount)
Expand Down Expand Up @@ -447,7 +447,7 @@ func TestChainSimulator_ExecuteWithTransferDataFails(t *testing.T) {
// register sovereign token identifier
// this will issue a new token on main chain and create a mapper between the identifiers
registerTokens(t, cs, wallet, &nonce, bridgeData.ESDTSafeAddress, token)
tokensMapper[token.Identifier] = chainSim.GetIssuedEsdtIdentifier(t, cs.GetNodeHandler(core.MetachainShardId), getTokenTicker(token.Identifier), token.Type.String())
tokensMapper[token.Identifier] = chainSim.GetIssuedEsdtIdentifier(t, cs, getTokenTicker(token.Identifier), token.Type.String())

// get contract from next shard
receiver := receiverContracts[receiverShardId]
Expand Down Expand Up @@ -512,7 +512,7 @@ func generateAccountsAndTokens(

account, accountAddrBytes := createNewAccount(cs, &accountShardId)
supply := big.NewInt(14556666767)
tokenId := chainSim.IssueFungible(t, cs, cs.GetNodeHandler(core.MetachainShardId), accountAddrBytes, &account.nonce, issueCost, "TKN", "TKN", 18, supply)
tokenId := chainSim.IssueFungible(t, cs, accountAddrBytes, &account.nonce, issueCost, "TKN", "TKN", 18, supply)
token := chainSim.ArgsDepositToken{
Identifier: tokenId,
Nonce: uint64(0),
Expand Down
12 changes: 6 additions & 6 deletions integrationTests/chainSimulator/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ func TransferESDTNFT(
func IssueFungible(
t *testing.T,
cs ChainSimulator,
nodeHandler process.NodeHandler,
sender []byte,
nonce *uint64,
issueCost *big.Int,
Expand All @@ -289,12 +288,13 @@ func IssueFungible(
txResult := SendTransaction(t, cs, sender, nonce, vm.ESDTSCAddress, issueCost, issueArgs, uint64(60000000))
RequireSuccessfulTransaction(t, txResult)

return GetIssuedEsdtIdentifier(t, nodeHandler, tokenTicker, core.FungibleESDT)
return GetIssuedEsdtIdentifier(t, cs, tokenTicker, core.FungibleESDT)
}

// GetIssuedEsdtIdentifier will return the token identifier for and issued token
func GetIssuedEsdtIdentifier(t *testing.T, nodeHandler process.NodeHandler, ticker string, tokenType string) string {
issuedTokens, err := nodeHandler.GetFacadeHandler().GetAllIssuedESDTs(tokenType)
func GetIssuedEsdtIdentifier(t *testing.T, cs ChainSimulator, ticker string, tokenType string) string {
esdtScAddressShardId := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(vm.ESDTSCAddress)
issuedTokens, err := cs.GetNodeHandler(esdtScAddressShardId).GetFacadeHandler().GetAllIssuedESDTs(tokenType)
require.Nil(t, err)
require.GreaterOrEqual(t, len(issuedTokens), 1, "no issued tokens found of type %s", tokenType)

Expand Down Expand Up @@ -382,7 +382,7 @@ func RegisterAndSetAllRoles(
"@" + fmt.Sprintf("%02X", numDecimals)
SendTransaction(t, cs, sender, nonce, vm.ESDTSCAddress, issueCost, registerArgs, uint64(60000000))

return GetIssuedEsdtIdentifier(t, cs.GetNodeHandler(core.MetachainShardId), esdtTicker, tokenType)
return GetIssuedEsdtIdentifier(t, cs, esdtTicker, tokenType)
}

// RegisterAndSetAllRolesDynamic will issue a dynamic esdt collection with all roles enabled
Expand All @@ -407,7 +407,7 @@ func RegisterAndSetAllRolesDynamic(
}
SendTransaction(t, cs, sender, nonce, vm.ESDTSCAddress, issueCost, registerArgs, uint64(60000000))

return GetIssuedEsdtIdentifier(t, cs.GetNodeHandler(core.MetachainShardId), esdtTicker, tokenType)
return GetIssuedEsdtIdentifier(t, cs, esdtTicker, tokenType)
}

func getTokenRegisterType(tokenType string) string {
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/chainSimulator/esdt/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestChainSimulator_IssueESDTWithPrefix(t *testing.T) {
tokenName := "Token"
tokenTicker := "TKN"
numDecimals := 18
issuedToken := chainSim.IssueFungible(t, cs, cs.GetNodeHandler(core.MetachainShardId), initialAddrBytes, &nonce, issueCost, tokenName, tokenTicker, numDecimals, initialSupply)
issuedToken := chainSim.IssueFungible(t, cs, initialAddrBytes, &nonce, issueCost, tokenName, tokenTicker, numDecimals, initialSupply)
require.True(t, strings.HasPrefix(issuedToken, tokenPrefix+"-"+tokenTicker+"-"))

// Step 3 - send issued esdt
Expand Down

0 comments on commit 139e848

Please sign in to comment.