From f06d075bd36c931246a11c81fc2d9060df32c4ac Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Tue, 25 Jun 2024 16:54:42 +0200 Subject: [PATCH 1/9] add test in proper directory Signed-off-by: salaheldinsoliman --- packages/evm/evmtest/GetBalance.abi | 1 + packages/evm/evmtest/GetBalance.bin | 1 + packages/evm/evmtest/GetBalance.sol | 27 +++++++ packages/evm/evmtest/contracts.go | 9 +++ .../vm/core/evm/evmtest/contractInstance.go | 17 +++++ packages/vm/core/evm/evmtest/evm_test.go | 75 +++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 packages/evm/evmtest/GetBalance.abi create mode 100644 packages/evm/evmtest/GetBalance.bin create mode 100644 packages/evm/evmtest/GetBalance.sol diff --git a/packages/evm/evmtest/GetBalance.abi b/packages/evm/evmtest/GetBalance.abi new file mode 100644 index 0000000000..7c76c6cbbf --- /dev/null +++ b/packages/evm/evmtest/GetBalance.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"agentID","type":"bytes"}],"name":"GotAgentID","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"baseBalance","type":"uint64"}],"name":"GotBaseBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftBalance","type":"uint256"}],"name":"GotNFTIDs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nativeTokenBalance","type":"uint256"}],"name":"GotNativeTokenBalance","type":"event"},{"inputs":[{"internalType":"bytes","name":"nativeTokenID","type":"bytes"}],"name":"getBalance","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/packages/evm/evmtest/GetBalance.bin b/packages/evm/evmtest/GetBalance.bin new file mode 100644 index 0000000000..dcf08c7827 --- /dev/null +++ b/packages/evm/evmtest/GetBalance.bin @@ -0,0 +1 @@ +608060405234801561000f575f80fd5b506108ef8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063d0fc35011461002d575b5f80fd5b610047600480360381019061004291906104c5565b610049565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100a6573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906100ce91906105ff565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516101029190610698565b60405180910390a15f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016101589190610727565b602060405180830381865afa158015610173573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101979190610784565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516101c891906107be565b60405180910390a15f60405180602001604052808581525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83866040518363ffffffff1660e01b81526004016102329291906107fe565b602060405180830381865afa15801561024d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102719190610866565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516102a291906108a0565b60405180910390a15f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b866040518263ffffffff1660e01b81526004016102f89190610727565b602060405180830381865afa158015610313573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103379190610866565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e541018160405161036891906108a0565b60405180910390a1505050505050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6103d782610391565b810181811067ffffffffffffffff821117156103f6576103f56103a1565b5b80604052505050565b5f610408610378565b905061041482826103ce565b919050565b5f67ffffffffffffffff821115610433576104326103a1565b5b61043c82610391565b9050602081019050919050565b828183375f83830152505050565b5f61046961046484610419565b6103ff565b9050828152602081018484840111156104855761048461038d565b5b610490848285610449565b509392505050565b5f82601f8301126104ac576104ab610389565b5b81356104bc848260208601610457565b91505092915050565b5f602082840312156104da576104d9610381565b5b5f82013567ffffffffffffffff8111156104f7576104f6610385565b5b61050384828501610498565b91505092915050565b5f80fd5b5f80fd5b5f5b83811015610531578082015181840152602081019050610516565b5f8484015250505050565b5f61054e61054984610419565b6103ff565b90508281526020810184848401111561056a5761056961038d565b5b610575848285610514565b509392505050565b5f82601f83011261059157610590610389565b5b81516105a184826020860161053c565b91505092915050565b5f602082840312156105bf576105be61050c565b5b6105c960206103ff565b90505f82015167ffffffffffffffff8111156105e8576105e7610510565b5b6105f48482850161057d565b5f8301525092915050565b5f6020828403121561061457610613610381565b5b5f82015167ffffffffffffffff81111561063157610630610385565b5b61063d848285016105aa565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61066a82610646565b6106748185610650565b9350610684818560208601610514565b61068d81610391565b840191505092915050565b5f6020820190508181035f8301526106b08184610660565b905092915050565b5f82825260208201905092915050565b5f6106d282610646565b6106dc81856106b8565b93506106ec818560208601610514565b6106f581610391565b840191505092915050565b5f602083015f8301518482035f86015261071a82826106c8565b9150508091505092915050565b5f6020820190508181035f83015261073f8184610700565b905092915050565b5f67ffffffffffffffff82169050919050565b61076381610747565b811461076d575f80fd5b50565b5f8151905061077e8161075a565b92915050565b5f6020828403121561079957610798610381565b5b5f6107a684828501610770565b91505092915050565b6107b881610747565b82525050565b5f6020820190506107d15f8301846107af565b92915050565b5f602083015f8301518482035f8601526107f182826106c8565b9150508091505092915050565b5f6040820190508181035f83015261081681856107d7565b9050818103602083015261082a8184610700565b90509392505050565b5f819050919050565b61084581610833565b811461084f575f80fd5b50565b5f815190506108608161083c565b92915050565b5f6020828403121561087b5761087a610381565b5b5f61088884828501610852565b91505092915050565b61089a81610833565b82525050565b5f6020820190506108b35f830184610891565b9291505056fea264697066735822122090eb26ecd9fcc4785bf94129a00cd83e3e9f7eee6f59bc51191d4984ac66195064736f6c63430008140033 \ No newline at end of file diff --git a/packages/evm/evmtest/GetBalance.sol b/packages/evm/evmtest/GetBalance.sol new file mode 100644 index 0000000000..88e1d0b98a --- /dev/null +++ b/packages/evm/evmtest/GetBalance.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "@iscmagic/ISC.sol"; + +contract GetBalance { + event GotAgentID(bytes agentID); + event GotBaseBalance(uint64 baseBalance); + event GotNativeTokenBalance(uint256 nativeTokenBalance); + event GotNFTIDs(uint256 nftBalance); + + function getBalance(bytes memory nativeTokenID) public { + ISCAgentID memory agentID = ISC.sandbox.getSenderAccount(); + emit GotAgentID(agentID.data); + + uint64 baseBalance = ISC.accounts.getL2BalanceBaseTokens(agentID); + emit GotBaseBalance(baseBalance); + + NativeTokenID memory id = NativeTokenID({ data: nativeTokenID}); + uint256 nativeTokens = ISC.accounts.getL2BalanceNativeTokens(id, agentID); + emit GotNativeTokenBalance(nativeTokens); + + uint256 nfts = ISC.accounts.getL2NFTAmount(agentID); + emit GotNFTIDs(nfts); + } +} \ No newline at end of file diff --git a/packages/evm/evmtest/contracts.go b/packages/evm/evmtest/contracts.go index 805eb11443..88f7929ead 100644 --- a/packages/evm/evmtest/contracts.go +++ b/packages/evm/evmtest/contracts.go @@ -54,6 +54,15 @@ var ( ISCTestContractBytecode = common.FromHex(strings.TrimSpace(iscTestContractBytecodeHex)) ) +//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../vm/core/evm/iscmagic` GetBalance.sol -o ." +var ( + //go:embed GetBalance.abi + GetBalanceContractABI string + //go:embed GetBalance.bin + GetBalanceContractBytecodeHex string + GetBalanceContractBytecode = common.FromHex(strings.TrimSpace(GetBalanceContractBytecodeHex)) +) + //go:generate solc --abi --bin --overwrite Fibonacci.sol -o . var ( //go:embed Fibonacci.abi diff --git a/packages/vm/core/evm/evmtest/contractInstance.go b/packages/vm/core/evm/evmtest/contractInstance.go index 53652d5d69..aa120efcf9 100644 --- a/packages/vm/core/evm/evmtest/contractInstance.go +++ b/packages/vm/core/evm/evmtest/contractInstance.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "fmt" "math/big" + "slices" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" @@ -152,6 +153,22 @@ func (e *EVMContractInstance) CallFnExpectEvent(opts []ethCallOptions, eventName return res } +// If a Solidity function emits multiple events, this function will return the first event that matches the given eventName +func (e *EVMContractInstance) CallFnExpectMultipleEvents(opts []ethCallOptions, eventName string, v interface{}, fnName string, args ...interface{}) CallFnResult { + res, err := e.CallFn(opts, fnName, args...) + require.NoError(e.chain.t, err) + require.Equal(e.chain.t, types.ReceiptStatusSuccessful, res.EVMReceipt.Status) + //require.Len(e.chain.t, res.EVMReceipt.Logs, len(eventNames)) + topic := e.abi.Events[eventName].ID + for _, log := range res.EVMReceipt.Logs { + if slices.Contains(log.Topics, topic) { + err = e.abi.UnpackIntoInterface(v, eventName, log.Data) + } + require.NoError(e.chain.t, err) + } + return res +} + func (e *EVMContractInstance) callView(fnName string, args []interface{}, v interface{}, blockNumberOrHash ...rpc.BlockNumberOrHash) error { e.chain.t.Logf("callView: %s %+v", fnName, args) callArguments, err := e.abi.Pack(fnName, args...) diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index 69ae8c0687..c01d43b96d 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -23,6 +23,7 @@ import ( "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/rpc" "github.com/samber/lo" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" iotago "github.com/iotaledger/iota.go/v3" @@ -2690,3 +2691,77 @@ func TestDisableMagicWrap(t *testing.T) { envWithMagicWrap := InitEVM(t, true) require.NotNil(t, envWithMagicWrap.getCode(envWithMagicWrap.ERC20BaseTokens(nil).address)) } + +func TestGetBalancea(t *testing.T) { + + env := InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) + + // create a new native token on L1 + foundry, tokenId, err := env.Chain.NewNativeTokenParams(100000000000000).CreateFoundry() + require.NoError(t, err) + // the token id in bytes, used to call the contract + nativeTokenIdBytes := isc.NativeTokenIDToBytes(tokenId) + + // mint some native tokens to the chain originator + err = env.Chain.MintTokens(foundry, 10000000, env.Chain.OriginatorPrivateKey) + require.NoError(t, err) + + // get the agentId of the contract deployer + senderAgentId := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) + + // test 1 + // get the actual base balance of the contract deployer + // and compare it with the balance returned by the contract + balance, _ := env.Chain.EVM().Balance(deployer, nil) + decimals := env.Chain.EVM().BaseToken().Decimals + var value uint64 + instance.CallFnExpectMultipleEvents(nil, "GotBaseBalance", &value, "getBalance", nativeTokenIdBytes) + real := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) + assert.Equal(t, balance, real) + + // test 2 + // get the agnetId of the contract deployer + // and compare it with the agentId returned by the contract + var agent_id []byte + instance.CallFnExpectMultipleEvents(nil, "GotAgentID", &agent_id, "getBalance", nativeTokenIdBytes) + assert.Equal(t, senderAgentId.Bytes(), agent_id) + + // test 3 + // get the native token balance of the contract deployer + // It should be 0, because the contract deployer has not received any native tokens yet + nativeBalance := new(big.Int) + instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIdBytes) + assert.Equal(t, int64(0), nativeBalance.Int64()) + + // test 4 + // send some native tokens to the contract deployer + // and check if the balance returned by the contract is correct + err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenId, senderAgentId, 100000, env.Chain.OriginatorPrivateKey) + require.NoError(t, err) + instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIdBytes) + assert.Equal(t, int64(100000), nativeBalance.Int64()) + + // test 5 + // mint an NFToken to the contract deployer + // and check if the balance returned by the contract is correct + mockMetaData := []byte("sesa") + nfti, info, err := env.Chain.Env.MintNFTL1(env.Chain.OriginatorPrivateKey, env.Chain.OriginatorAddress, mockMetaData) + require.NoError(t, err) + env.Chain.MustDepositNFT(nfti, env.Chain.OriginatorAgentID, env.Chain.OriginatorPrivateKey) + + transfer := isc.NewEmptyAssets() + transfer.AddNFTs(info.NFTID) + + // send the NFT to the contract deployer + err = env.Chain.SendFromL2ToL2Account(transfer, senderAgentId, env.Chain.OriginatorPrivateKey) + require.NoError(t, err) + + // get the NFT balance of the contract deployer + nftBalance := new(big.Int) + instance.CallFnExpectMultipleEvents(nil, "GotNFTIDs", &nftBalance, "getBalance", nativeTokenIdBytes) + assert.Equal(t, int64(1), nftBalance.Int64()) + +} From d2e84a3e791976cf33a8c096ecc76532348c3154 Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Tue, 25 Jun 2024 17:09:21 +0200 Subject: [PATCH 2/9] address linter issues Signed-off-by: salaheldinsoliman --- .../vm/core/evm/evmtest/contractInstance.go | 1 - packages/vm/core/evm/evmtest/evm_test.go | 32 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/vm/core/evm/evmtest/contractInstance.go b/packages/vm/core/evm/evmtest/contractInstance.go index aa120efcf9..8351761c97 100644 --- a/packages/vm/core/evm/evmtest/contractInstance.go +++ b/packages/vm/core/evm/evmtest/contractInstance.go @@ -158,7 +158,6 @@ func (e *EVMContractInstance) CallFnExpectMultipleEvents(opts []ethCallOptions, res, err := e.CallFn(opts, fnName, args...) require.NoError(e.chain.t, err) require.Equal(e.chain.t, types.ReceiptStatusSuccessful, res.EVMReceipt.Status) - //require.Len(e.chain.t, res.EVMReceipt.Logs, len(eventNames)) topic := e.abi.Events[eventName].ID for _, log := range res.EVMReceipt.Logs { if slices.Contains(log.Topics, topic) { diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index c01d43b96d..5aaa66e031 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -2692,25 +2692,24 @@ func TestDisableMagicWrap(t *testing.T) { require.NotNil(t, envWithMagicWrap.getCode(envWithMagicWrap.ERC20BaseTokens(nil).address)) } -func TestGetBalancea(t *testing.T) { - +func TestGetBalance(t *testing.T) { env := InitEVMWithSolo(t, solo.New(t), true) privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) // create a new native token on L1 - foundry, tokenId, err := env.Chain.NewNativeTokenParams(100000000000000).CreateFoundry() + foundry, tokenID, err := env.Chain.NewNativeTokenParams(100000000000000).CreateFoundry() require.NoError(t, err) // the token id in bytes, used to call the contract - nativeTokenIdBytes := isc.NativeTokenIDToBytes(tokenId) + nativeTokenIDBytes := isc.NativeTokenIDToBytes(tokenID) // mint some native tokens to the chain originator err = env.Chain.MintTokens(foundry, 10000000, env.Chain.OriginatorPrivateKey) require.NoError(t, err) // get the agentId of the contract deployer - senderAgentId := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) + senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) // test 1 // get the actual base balance of the contract deployer @@ -2718,30 +2717,30 @@ func TestGetBalancea(t *testing.T) { balance, _ := env.Chain.EVM().Balance(deployer, nil) decimals := env.Chain.EVM().BaseToken().Decimals var value uint64 - instance.CallFnExpectMultipleEvents(nil, "GotBaseBalance", &value, "getBalance", nativeTokenIdBytes) - real := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) - assert.Equal(t, balance, real) + instance.CallFnExpectMultipleEvents(nil, "GotBaseBalance", &value, "getBalance", nativeTokenIDBytes) + realBalance := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) + assert.Equal(t, balance, realBalance) // test 2 // get the agnetId of the contract deployer // and compare it with the agentId returned by the contract - var agent_id []byte - instance.CallFnExpectMultipleEvents(nil, "GotAgentID", &agent_id, "getBalance", nativeTokenIdBytes) - assert.Equal(t, senderAgentId.Bytes(), agent_id) + var adgntID []byte + instance.CallFnExpectMultipleEvents(nil, "GotAgentID", &adgntID, "getBalance", nativeTokenIDBytes) + assert.Equal(t, senderAgentID.Bytes(), adgntID) // test 3 // get the native token balance of the contract deployer // It should be 0, because the contract deployer has not received any native tokens yet nativeBalance := new(big.Int) - instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIdBytes) + instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIDBytes) assert.Equal(t, int64(0), nativeBalance.Int64()) // test 4 // send some native tokens to the contract deployer // and check if the balance returned by the contract is correct - err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenId, senderAgentId, 100000, env.Chain.OriginatorPrivateKey) + err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenID, senderAgentID, 100000, env.Chain.OriginatorPrivateKey) require.NoError(t, err) - instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIdBytes) + instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIDBytes) assert.Equal(t, int64(100000), nativeBalance.Int64()) // test 5 @@ -2756,12 +2755,11 @@ func TestGetBalancea(t *testing.T) { transfer.AddNFTs(info.NFTID) // send the NFT to the contract deployer - err = env.Chain.SendFromL2ToL2Account(transfer, senderAgentId, env.Chain.OriginatorPrivateKey) + err = env.Chain.SendFromL2ToL2Account(transfer, senderAgentID, env.Chain.OriginatorPrivateKey) require.NoError(t, err) // get the NFT balance of the contract deployer nftBalance := new(big.Int) - instance.CallFnExpectMultipleEvents(nil, "GotNFTIDs", &nftBalance, "getBalance", nativeTokenIdBytes) + instance.CallFnExpectMultipleEvents(nil, "GotNFTIDs", &nftBalance, "getBalance", nativeTokenIDBytes) assert.Equal(t, int64(1), nftBalance.Int64()) - } From b134710803d264ccaa2d24e4310dfd2060f0a103 Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Tue, 2 Jul 2024 16:26:46 +0200 Subject: [PATCH 3/9] separate tests and contract functions --- packages/evm/evmtest/GetBalance.abi | 2 +- packages/evm/evmtest/GetBalance.bin | 2 +- packages/evm/evmtest/GetBalance.sol | 24 ++++++-- packages/vm/core/evm/evmtest/evm_test.go | 74 ++++++++++++++---------- 4 files changed, 65 insertions(+), 37 deletions(-) diff --git a/packages/evm/evmtest/GetBalance.abi b/packages/evm/evmtest/GetBalance.abi index 7c76c6cbbf..bf80089cdf 100644 --- a/packages/evm/evmtest/GetBalance.abi +++ b/packages/evm/evmtest/GetBalance.abi @@ -1 +1 @@ -[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"agentID","type":"bytes"}],"name":"GotAgentID","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"baseBalance","type":"uint64"}],"name":"GotBaseBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftBalance","type":"uint256"}],"name":"GotNFTIDs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nativeTokenBalance","type":"uint256"}],"name":"GotNativeTokenBalance","type":"event"},{"inputs":[{"internalType":"bytes","name":"nativeTokenID","type":"bytes"}],"name":"getBalance","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"agentID","type":"bytes"}],"name":"GotAgentID","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"baseBalance","type":"uint64"}],"name":"GotBaseBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftBalance","type":"uint256"}],"name":"GotNFTIDs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nativeTokenBalance","type":"uint256"}],"name":"GotNativeTokenBalance","type":"event"},{"inputs":[],"name":"getAgentID","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceBaseTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"nativeTokenID","type":"bytes"}],"name":"getBalanceNativeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/packages/evm/evmtest/GetBalance.bin b/packages/evm/evmtest/GetBalance.bin index dcf08c7827..ddec8f66d3 100644 --- a/packages/evm/evmtest/GetBalance.bin +++ b/packages/evm/evmtest/GetBalance.bin @@ -1 +1 @@ -608060405234801561000f575f80fd5b506108ef8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063d0fc35011461002d575b5f80fd5b610047600480360381019061004291906104c5565b610049565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100a6573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906100ce91906105ff565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516101029190610698565b60405180910390a15f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016101589190610727565b602060405180830381865afa158015610173573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101979190610784565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516101c891906107be565b60405180910390a15f60405180602001604052808581525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83866040518363ffffffff1660e01b81526004016102329291906107fe565b602060405180830381865afa15801561024d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102719190610866565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516102a291906108a0565b60405180910390a15f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b866040518263ffffffff1660e01b81526004016102f89190610727565b602060405180830381865afa158015610313573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103379190610866565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e541018160405161036891906108a0565b60405180910390a1505050505050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6103d782610391565b810181811067ffffffffffffffff821117156103f6576103f56103a1565b5b80604052505050565b5f610408610378565b905061041482826103ce565b919050565b5f67ffffffffffffffff821115610433576104326103a1565b5b61043c82610391565b9050602081019050919050565b828183375f83830152505050565b5f61046961046484610419565b6103ff565b9050828152602081018484840111156104855761048461038d565b5b610490848285610449565b509392505050565b5f82601f8301126104ac576104ab610389565b5b81356104bc848260208601610457565b91505092915050565b5f602082840312156104da576104d9610381565b5b5f82013567ffffffffffffffff8111156104f7576104f6610385565b5b61050384828501610498565b91505092915050565b5f80fd5b5f80fd5b5f5b83811015610531578082015181840152602081019050610516565b5f8484015250505050565b5f61054e61054984610419565b6103ff565b90508281526020810184848401111561056a5761056961038d565b5b610575848285610514565b509392505050565b5f82601f83011261059157610590610389565b5b81516105a184826020860161053c565b91505092915050565b5f602082840312156105bf576105be61050c565b5b6105c960206103ff565b90505f82015167ffffffffffffffff8111156105e8576105e7610510565b5b6105f48482850161057d565b5f8301525092915050565b5f6020828403121561061457610613610381565b5b5f82015167ffffffffffffffff81111561063157610630610385565b5b61063d848285016105aa565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61066a82610646565b6106748185610650565b9350610684818560208601610514565b61068d81610391565b840191505092915050565b5f6020820190508181035f8301526106b08184610660565b905092915050565b5f82825260208201905092915050565b5f6106d282610646565b6106dc81856106b8565b93506106ec818560208601610514565b6106f581610391565b840191505092915050565b5f602083015f8301518482035f86015261071a82826106c8565b9150508091505092915050565b5f6020820190508181035f83015261073f8184610700565b905092915050565b5f67ffffffffffffffff82169050919050565b61076381610747565b811461076d575f80fd5b50565b5f8151905061077e8161075a565b92915050565b5f6020828403121561079957610798610381565b5b5f6107a684828501610770565b91505092915050565b6107b881610747565b82525050565b5f6020820190506107d15f8301846107af565b92915050565b5f602083015f8301518482035f8601526107f182826106c8565b9150508091505092915050565b5f6040820190508181035f83015261081681856107d7565b9050818103602083015261082a8184610700565b90509392505050565b5f819050919050565b61084581610833565b811461084f575f80fd5b50565b5f815190506108608161083c565b92915050565b5f6020828403121561087b5761087a610381565b5b5f61088884828501610852565b91505092915050565b61089a81610833565b82525050565b5f6020820190506108b35f830184610891565b9291505056fea264697066735822122090eb26ecd9fcc4785bf94129a00cd83e3e9f7eee6f59bc51191d4984ac66195064736f6c63430008140033 \ No newline at end of file +608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea26469706673582212202c9d1af4136de267ede721d5e5ea147744597e332cd762811459a05c0013200264736f6c63430008140033 \ No newline at end of file diff --git a/packages/evm/evmtest/GetBalance.sol b/packages/evm/evmtest/GetBalance.sol index 88e1d0b98a..35ae87d59b 100644 --- a/packages/evm/evmtest/GetBalance.sol +++ b/packages/evm/evmtest/GetBalance.sol @@ -10,18 +10,30 @@ contract GetBalance { event GotNativeTokenBalance(uint256 nativeTokenBalance); event GotNFTIDs(uint256 nftBalance); - function getBalance(bytes memory nativeTokenID) public { + function getBalanceBaseTokens() public { ISCAgentID memory agentID = ISC.sandbox.getSenderAccount(); - emit GotAgentID(agentID.data); - uint64 baseBalance = ISC.accounts.getL2BalanceBaseTokens(agentID); emit GotBaseBalance(baseBalance); + } - NativeTokenID memory id = NativeTokenID({ data: nativeTokenID}); - uint256 nativeTokens = ISC.accounts.getL2BalanceNativeTokens(id, agentID); + function getBalanceNativeTokens(bytes memory nativeTokenID) public { + ISCAgentID memory agentID = ISC.sandbox.getSenderAccount(); + NativeTokenID memory id = NativeTokenID({data: nativeTokenID}); + uint256 nativeTokens = ISC.accounts.getL2BalanceNativeTokens( + id, + agentID + ); emit GotNativeTokenBalance(nativeTokens); + } + function getBalanceNFTs() public { + ISCAgentID memory agentID = ISC.sandbox.getSenderAccount(); uint256 nfts = ISC.accounts.getL2NFTAmount(agentID); emit GotNFTIDs(nfts); } -} \ No newline at end of file + + function getAgentID() public { + ISCAgentID memory agentID = ISC.sandbox.getSenderAccount(); + emit GotAgentID(agentID.data); + } +} diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index 4b92da09c2..4b19439fdd 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -2731,7 +2731,21 @@ func TestDisableMagicWrap(t *testing.T) { require.NotNil(t, envWithMagicWrap.getCode(envWithMagicWrap.ERC20BaseTokens(nil).address)) } -func TestGetBalance(t *testing.T) { +func TestBaseBalance(t *testing.T) { + env := InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) + + balance, _ := env.Chain.EVM().Balance(deployer, nil) + decimals := env.Chain.EVM().BaseToken().Decimals + var value uint64 + instance.CallFnExpectEvent(nil, "GotBaseBalance", &value, "getBalanceBaseTokens") + realBalance := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) + assert.Equal(t, balance, realBalance) +} + +func TestNativeBalance(t *testing.T) { env := InitEVMWithSolo(t, solo.New(t), true) privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() @@ -2750,39 +2764,25 @@ func TestGetBalance(t *testing.T) { // get the agentId of the contract deployer senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) - // test 1 - // get the actual base balance of the contract deployer - // and compare it with the balance returned by the contract - balance, _ := env.Chain.EVM().Balance(deployer, nil) - decimals := env.Chain.EVM().BaseToken().Decimals - var value uint64 - instance.CallFnExpectMultipleEvents(nil, "GotBaseBalance", &value, "getBalance", nativeTokenIDBytes) - realBalance := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) - assert.Equal(t, balance, realBalance) - - // test 2 - // get the agnetId of the contract deployer - // and compare it with the agentId returned by the contract - var adgntID []byte - instance.CallFnExpectMultipleEvents(nil, "GotAgentID", &adgntID, "getBalance", nativeTokenIDBytes) - assert.Equal(t, senderAgentID.Bytes(), adgntID) - - // test 3 - // get the native token balance of the contract deployer - // It should be 0, because the contract deployer has not received any native tokens yet - nativeBalance := new(big.Int) - instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIDBytes) - assert.Equal(t, int64(0), nativeBalance.Int64()) - - // test 4 // send some native tokens to the contract deployer // and check if the balance returned by the contract is correct err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenID, senderAgentID, 100000, env.Chain.OriginatorPrivateKey) require.NoError(t, err) - instance.CallFnExpectMultipleEvents(nil, "GotNativeTokenBalance", &nativeBalance, "getBalance", nativeTokenIDBytes) + + nativeBalance := new(big.Int) + instance.CallFnExpectEvent(nil, "GotNativeTokenBalance", &nativeBalance, "getBalanceNativeTokens", nativeTokenIDBytes) assert.Equal(t, int64(100000), nativeBalance.Int64()) +} + +func TestNFTBalance(t *testing.T) { + env := InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) + + // get the agentId of the contract deployer + senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) - // test 5 // mint an NFToken to the contract deployer // and check if the balance returned by the contract is correct mockMetaData := []byte("sesa") @@ -2799,6 +2799,22 @@ func TestGetBalance(t *testing.T) { // get the NFT balance of the contract deployer nftBalance := new(big.Int) - instance.CallFnExpectMultipleEvents(nil, "GotNFTIDs", &nftBalance, "getBalance", nativeTokenIDBytes) + instance.CallFnExpectEvent(nil, "GotNFTIDs", &nftBalance, "getBalanceNFTs") assert.Equal(t, int64(1), nftBalance.Int64()) } + +func TestAgentID(t *testing.T) { + env := InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) + + // get the agentId of the contract deployer + senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) + + // get the agnetId of the contract deployer + // and compare it with the agentId returned by the contract + var agentID []byte + instance.CallFnExpectMultipleEvents(nil, "GotAgentID", &agentID, "getAgentID") + assert.Equal(t, senderAgentID.Bytes(), agentID) +} From 3e29bb60d00d1a586e7a7c41454bfa0c60031d09 Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Tue, 2 Jul 2024 16:27:44 +0200 Subject: [PATCH 4/9] remove CallFnExpectMultipleEvents --- packages/vm/core/evm/evmtest/contractInstance.go | 16 ---------------- packages/vm/core/evm/evmtest/evm_test.go | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/vm/core/evm/evmtest/contractInstance.go b/packages/vm/core/evm/evmtest/contractInstance.go index 8351761c97..53652d5d69 100644 --- a/packages/vm/core/evm/evmtest/contractInstance.go +++ b/packages/vm/core/evm/evmtest/contractInstance.go @@ -4,7 +4,6 @@ import ( "crypto/ecdsa" "fmt" "math/big" - "slices" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" @@ -153,21 +152,6 @@ func (e *EVMContractInstance) CallFnExpectEvent(opts []ethCallOptions, eventName return res } -// If a Solidity function emits multiple events, this function will return the first event that matches the given eventName -func (e *EVMContractInstance) CallFnExpectMultipleEvents(opts []ethCallOptions, eventName string, v interface{}, fnName string, args ...interface{}) CallFnResult { - res, err := e.CallFn(opts, fnName, args...) - require.NoError(e.chain.t, err) - require.Equal(e.chain.t, types.ReceiptStatusSuccessful, res.EVMReceipt.Status) - topic := e.abi.Events[eventName].ID - for _, log := range res.EVMReceipt.Logs { - if slices.Contains(log.Topics, topic) { - err = e.abi.UnpackIntoInterface(v, eventName, log.Data) - } - require.NoError(e.chain.t, err) - } - return res -} - func (e *EVMContractInstance) callView(fnName string, args []interface{}, v interface{}, blockNumberOrHash ...rpc.BlockNumberOrHash) error { e.chain.t.Logf("callView: %s %+v", fnName, args) callArguments, err := e.abi.Pack(fnName, args...) diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index 4b19439fdd..6b31dd5df4 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -2815,6 +2815,6 @@ func TestAgentID(t *testing.T) { // get the agnetId of the contract deployer // and compare it with the agentId returned by the contract var agentID []byte - instance.CallFnExpectMultipleEvents(nil, "GotAgentID", &agentID, "getAgentID") + instance.CallFnExpectEvent(nil, "GotAgentID", &agentID, "getAgentID") assert.Equal(t, senderAgentID.Bytes(), agentID) } From dc08621014e4d2c0cac418601afbbc15093a677d Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Tue, 2 Jul 2024 16:38:16 +0200 Subject: [PATCH 5/9] move GetBalance.sol to a subdir --- packages/evm/evmtest/GetBalance.bin | 2 +- packages/evm/evmtest/contracts.go | 2 +- packages/evm/evmtest/{ => wiki-how-tos}/GetBalance.sol | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename packages/evm/evmtest/{ => wiki-how-tos}/GetBalance.sol (100%) diff --git a/packages/evm/evmtest/GetBalance.bin b/packages/evm/evmtest/GetBalance.bin index ddec8f66d3..5ff838c331 100644 --- a/packages/evm/evmtest/GetBalance.bin +++ b/packages/evm/evmtest/GetBalance.bin @@ -1 +1 @@ -608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea26469706673582212202c9d1af4136de267ede721d5e5ea147744597e332cd762811459a05c0013200264736f6c63430008140033 \ No newline at end of file +608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea2646970667358221220c1ba20295d4fa6cd9ff051ee5ed542a74df5cd6c0f96738919b6e8f944879bec64736f6c63430008140033 \ No newline at end of file diff --git a/packages/evm/evmtest/contracts.go b/packages/evm/evmtest/contracts.go index 88f7929ead..5db7e95333 100644 --- a/packages/evm/evmtest/contracts.go +++ b/packages/evm/evmtest/contracts.go @@ -54,7 +54,7 @@ var ( ISCTestContractBytecode = common.FromHex(strings.TrimSpace(iscTestContractBytecodeHex)) ) -//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../vm/core/evm/iscmagic` GetBalance.sol -o ." +//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../vm/core/evm/iscmagic` ./wiki-how-tos/GetBalance.sol -o ." var ( //go:embed GetBalance.abi GetBalanceContractABI string diff --git a/packages/evm/evmtest/GetBalance.sol b/packages/evm/evmtest/wiki-how-tos/GetBalance.sol similarity index 100% rename from packages/evm/evmtest/GetBalance.sol rename to packages/evm/evmtest/wiki-how-tos/GetBalance.sol From 0274236d03c7bcd2e0652e8f4b0fbcc4e0a0ff27 Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Fri, 5 Jul 2024 12:20:56 +0200 Subject: [PATCH 6/9] restructure wiki-howtos --- packages/evm/evmtest/contracts.go | 9 -- .../evm/evmtest/wiki-how-tos/GetBalance.abi | 1 + .../evm/evmtest/wiki-how-tos/GetBalance.bin | 1 + .../evm/evmtest/wiki-how-tos/how_tos_test.go | 114 ++++++++++++++++++ 4 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 packages/evm/evmtest/wiki-how-tos/GetBalance.abi create mode 100644 packages/evm/evmtest/wiki-how-tos/GetBalance.bin create mode 100644 packages/evm/evmtest/wiki-how-tos/how_tos_test.go diff --git a/packages/evm/evmtest/contracts.go b/packages/evm/evmtest/contracts.go index 5db7e95333..805eb11443 100644 --- a/packages/evm/evmtest/contracts.go +++ b/packages/evm/evmtest/contracts.go @@ -54,15 +54,6 @@ var ( ISCTestContractBytecode = common.FromHex(strings.TrimSpace(iscTestContractBytecodeHex)) ) -//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../vm/core/evm/iscmagic` ./wiki-how-tos/GetBalance.sol -o ." -var ( - //go:embed GetBalance.abi - GetBalanceContractABI string - //go:embed GetBalance.bin - GetBalanceContractBytecodeHex string - GetBalanceContractBytecode = common.FromHex(strings.TrimSpace(GetBalanceContractBytecodeHex)) -) - //go:generate solc --abi --bin --overwrite Fibonacci.sol -o . var ( //go:embed Fibonacci.abi diff --git a/packages/evm/evmtest/wiki-how-tos/GetBalance.abi b/packages/evm/evmtest/wiki-how-tos/GetBalance.abi new file mode 100644 index 0000000000..bf80089cdf --- /dev/null +++ b/packages/evm/evmtest/wiki-how-tos/GetBalance.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"agentID","type":"bytes"}],"name":"GotAgentID","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"baseBalance","type":"uint64"}],"name":"GotBaseBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftBalance","type":"uint256"}],"name":"GotNFTIDs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nativeTokenBalance","type":"uint256"}],"name":"GotNativeTokenBalance","type":"event"},{"inputs":[],"name":"getAgentID","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceBaseTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"nativeTokenID","type":"bytes"}],"name":"getBalanceNativeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/packages/evm/evmtest/wiki-how-tos/GetBalance.bin b/packages/evm/evmtest/wiki-how-tos/GetBalance.bin new file mode 100644 index 0000000000..ddec8f66d3 --- /dev/null +++ b/packages/evm/evmtest/wiki-how-tos/GetBalance.bin @@ -0,0 +1 @@ +608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea26469706673582212202c9d1af4136de267ede721d5e5ea147744597e332cd762811459a05c0013200264736f6c63430008140033 \ No newline at end of file diff --git a/packages/evm/evmtest/wiki-how-tos/how_tos_test.go b/packages/evm/evmtest/wiki-how-tos/how_tos_test.go new file mode 100644 index 0000000000..26f1ada071 --- /dev/null +++ b/packages/evm/evmtest/wiki-how-tos/how_tos_test.go @@ -0,0 +1,114 @@ +package wikihowtos_test + +import ( + _ "embed" + "math/big" + "strings" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/iotaledger/wasp/packages/isc" + "github.com/iotaledger/wasp/packages/solo" + "github.com/iotaledger/wasp/packages/util" + "github.com/iotaledger/wasp/packages/vm/core/evm/evmtest" +) + +//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../../vm/core/evm/iscmagic` GetBalance.sol -o ." +var ( + //go:embed GetBalance.abi + GetBalanceContractABI string + //go:embed GetBalance.bin + GetBalanceContractBytecodeHex string + GetBalanceContractBytecode = common.FromHex(strings.TrimSpace(GetBalanceContractBytecodeHex)) +) + +func TestBaseBalance(t *testing.T) { + env := evmtest.InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, GetBalanceContractABI, GetBalanceContractBytecode) + + balance, _ := env.Chain.EVM().Balance(deployer, nil) + decimals := env.Chain.EVM().BaseToken().Decimals + var value uint64 + instance.CallFnExpectEvent(nil, "GotBaseBalance", &value, "getBalanceBaseTokens") + realBalance := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) + assert.Equal(t, balance, realBalance) +} + +func TestNativeBalance(t *testing.T) { + env := evmtest.InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, GetBalanceContractABI, GetBalanceContractBytecode) + + // create a new native token on L1 + foundry, tokenID, err := env.Chain.NewNativeTokenParams(100000000000000).CreateFoundry() + require.NoError(t, err) + // the token id in bytes, used to call the contract + nativeTokenIDBytes := isc.NativeTokenIDToBytes(tokenID) + + // mint some native tokens to the chain originator + err = env.Chain.MintTokens(foundry, 10000000, env.Chain.OriginatorPrivateKey) + require.NoError(t, err) + + // get the agentId of the contract deployer + senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) + + // send some native tokens to the contract deployer + // and check if the balance returned by the contract is correct + err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenID, senderAgentID, 100000, env.Chain.OriginatorPrivateKey) + require.NoError(t, err) + + nativeBalance := new(big.Int) + instance.CallFnExpectEvent(nil, "GotNativeTokenBalance", &nativeBalance, "getBalanceNativeTokens", nativeTokenIDBytes) + assert.Equal(t, int64(100000), nativeBalance.Int64()) +} + +func TestNFTBalance(t *testing.T) { + env := evmtest.InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, GetBalanceContractABI, GetBalanceContractBytecode) + + // get the agentId of the contract deployer + senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) + + // mint an NFToken to the contract deployer + // and check if the balance returned by the contract is correct + mockMetaData := []byte("sesa") + nfti, info, err := env.Chain.Env.MintNFTL1(env.Chain.OriginatorPrivateKey, env.Chain.OriginatorAddress, mockMetaData) + require.NoError(t, err) + env.Chain.MustDepositNFT(nfti, env.Chain.OriginatorAgentID, env.Chain.OriginatorPrivateKey) + + transfer := isc.NewEmptyAssets() + transfer.AddNFTs(info.NFTID) + + // send the NFT to the contract deployer + err = env.Chain.SendFromL2ToL2Account(transfer, senderAgentID, env.Chain.OriginatorPrivateKey) + require.NoError(t, err) + + // get the NFT balance of the contract deployer + nftBalance := new(big.Int) + instance.CallFnExpectEvent(nil, "GotNFTIDs", &nftBalance, "getBalanceNFTs") + assert.Equal(t, int64(1), nftBalance.Int64()) +} + +func TestAgentID(t *testing.T) { + env := evmtest.InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, GetBalanceContractABI, GetBalanceContractBytecode) + + // get the agentId of the contract deployer + senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) + + // get the agnetId of the contract deployer + // and compare it with the agentId returned by the contract + var agentID []byte + instance.CallFnExpectEvent(nil, "GotAgentID", &agentID, "getAgentID") + assert.Equal(t, senderAgentID.Bytes(), agentID) +} From c312b1b65d33a16a2c9765cc904306a7a10f1282 Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Fri, 5 Jul 2024 12:21:14 +0200 Subject: [PATCH 7/9] restructure wiki-howtos --- packages/vm/core/evm/evmtest/evm_test.go | 89 ------------------------ 1 file changed, 89 deletions(-) diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index 6b31dd5df4..437e7f2cef 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/rpc" "github.com/samber/lo" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" iotago "github.com/iotaledger/iota.go/v3" @@ -2730,91 +2729,3 @@ func TestDisableMagicWrap(t *testing.T) { envWithMagicWrap := InitEVM(t, true) require.NotNil(t, envWithMagicWrap.getCode(envWithMagicWrap.ERC20BaseTokens(nil).address)) } - -func TestBaseBalance(t *testing.T) { - env := InitEVMWithSolo(t, solo.New(t), true) - privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() - - instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) - - balance, _ := env.Chain.EVM().Balance(deployer, nil) - decimals := env.Chain.EVM().BaseToken().Decimals - var value uint64 - instance.CallFnExpectEvent(nil, "GotBaseBalance", &value, "getBalanceBaseTokens") - realBalance := util.BaseTokensDecimalsToEthereumDecimals(value, decimals) - assert.Equal(t, balance, realBalance) -} - -func TestNativeBalance(t *testing.T) { - env := InitEVMWithSolo(t, solo.New(t), true) - privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() - - instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) - - // create a new native token on L1 - foundry, tokenID, err := env.Chain.NewNativeTokenParams(100000000000000).CreateFoundry() - require.NoError(t, err) - // the token id in bytes, used to call the contract - nativeTokenIDBytes := isc.NativeTokenIDToBytes(tokenID) - - // mint some native tokens to the chain originator - err = env.Chain.MintTokens(foundry, 10000000, env.Chain.OriginatorPrivateKey) - require.NoError(t, err) - - // get the agentId of the contract deployer - senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) - - // send some native tokens to the contract deployer - // and check if the balance returned by the contract is correct - err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenID, senderAgentID, 100000, env.Chain.OriginatorPrivateKey) - require.NoError(t, err) - - nativeBalance := new(big.Int) - instance.CallFnExpectEvent(nil, "GotNativeTokenBalance", &nativeBalance, "getBalanceNativeTokens", nativeTokenIDBytes) - assert.Equal(t, int64(100000), nativeBalance.Int64()) -} - -func TestNFTBalance(t *testing.T) { - env := InitEVMWithSolo(t, solo.New(t), true) - privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() - - instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) - - // get the agentId of the contract deployer - senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) - - // mint an NFToken to the contract deployer - // and check if the balance returned by the contract is correct - mockMetaData := []byte("sesa") - nfti, info, err := env.Chain.Env.MintNFTL1(env.Chain.OriginatorPrivateKey, env.Chain.OriginatorAddress, mockMetaData) - require.NoError(t, err) - env.Chain.MustDepositNFT(nfti, env.Chain.OriginatorAgentID, env.Chain.OriginatorPrivateKey) - - transfer := isc.NewEmptyAssets() - transfer.AddNFTs(info.NFTID) - - // send the NFT to the contract deployer - err = env.Chain.SendFromL2ToL2Account(transfer, senderAgentID, env.Chain.OriginatorPrivateKey) - require.NoError(t, err) - - // get the NFT balance of the contract deployer - nftBalance := new(big.Int) - instance.CallFnExpectEvent(nil, "GotNFTIDs", &nftBalance, "getBalanceNFTs") - assert.Equal(t, int64(1), nftBalance.Int64()) -} - -func TestAgentID(t *testing.T) { - env := InitEVMWithSolo(t, solo.New(t), true) - privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() - - instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode) - - // get the agentId of the contract deployer - senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer) - - // get the agnetId of the contract deployer - // and compare it with the agentId returned by the contract - var agentID []byte - instance.CallFnExpectEvent(nil, "GotAgentID", &agentID, "getAgentID") - assert.Equal(t, senderAgentID.Bytes(), agentID) -} From a85dc09b2ee054d0335cebeeacba3d2dd68bd21d Mon Sep 17 00:00:00 2001 From: salaheldinsoliman Date: Fri, 5 Jul 2024 12:25:56 +0200 Subject: [PATCH 8/9] remove bin and abi files from evmtest --- packages/evm/evmtest/GetBalance.abi | 1 - packages/evm/evmtest/GetBalance.bin | 1 - 2 files changed, 2 deletions(-) delete mode 100644 packages/evm/evmtest/GetBalance.abi delete mode 100644 packages/evm/evmtest/GetBalance.bin diff --git a/packages/evm/evmtest/GetBalance.abi b/packages/evm/evmtest/GetBalance.abi deleted file mode 100644 index bf80089cdf..0000000000 --- a/packages/evm/evmtest/GetBalance.abi +++ /dev/null @@ -1 +0,0 @@ -[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"agentID","type":"bytes"}],"name":"GotAgentID","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"baseBalance","type":"uint64"}],"name":"GotBaseBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftBalance","type":"uint256"}],"name":"GotNFTIDs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nativeTokenBalance","type":"uint256"}],"name":"GotNativeTokenBalance","type":"event"},{"inputs":[],"name":"getAgentID","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceBaseTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"nativeTokenID","type":"bytes"}],"name":"getBalanceNativeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/packages/evm/evmtest/GetBalance.bin b/packages/evm/evmtest/GetBalance.bin deleted file mode 100644 index 5ff838c331..0000000000 --- a/packages/evm/evmtest/GetBalance.bin +++ /dev/null @@ -1 +0,0 @@ -608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea2646970667358221220c1ba20295d4fa6cd9ff051ee5ed542a74df5cd6c0f96738919b6e8f944879bec64736f6c63430008140033 \ No newline at end of file From 204b27ff0c61785568079d97287c85c3aeb8122b Mon Sep 17 00:00:00 2001 From: Jorge Silva Date: Fri, 5 Jul 2024 12:25:41 +0100 Subject: [PATCH 9/9] add wiki how tos to solidity compile makefile task --- Makefile | 1 + packages/evm/evmtest/wiki-how-tos/GetBalance.bin | 1 - .../evm/evmtest/{wiki-how-tos => wiki_how_tos}/GetBalance.abi | 0 packages/evm/evmtest/wiki_how_tos/GetBalance.bin | 1 + .../evm/evmtest/{wiki-how-tos => wiki_how_tos}/GetBalance.sol | 0 .../evm/evmtest/{wiki-how-tos => wiki_how_tos}/how_tos_test.go | 2 +- 6 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 packages/evm/evmtest/wiki-how-tos/GetBalance.bin rename packages/evm/evmtest/{wiki-how-tos => wiki_how_tos}/GetBalance.abi (100%) create mode 100644 packages/evm/evmtest/wiki_how_tos/GetBalance.bin rename packages/evm/evmtest/{wiki-how-tos => wiki_how_tos}/GetBalance.sol (100%) rename packages/evm/evmtest/{wiki-how-tos => wiki_how_tos}/how_tos_test.go (99%) diff --git a/Makefile b/Makefile index 368314c3d2..6e48fdc995 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ wasm: compile-solidity: cd packages/vm/core/evm/iscmagic && go generate cd packages/evm/evmtest && go generate + cd packages/evm/evmtest/wiki_how_tos && go generate build-cli: cd tools/wasp-cli && go mod tidy && go build -ldflags $(BUILD_LD_FLAGS) -tags ${WASP_CLI_TAGS} -o ../../ diff --git a/packages/evm/evmtest/wiki-how-tos/GetBalance.bin b/packages/evm/evmtest/wiki-how-tos/GetBalance.bin deleted file mode 100644 index ddec8f66d3..0000000000 --- a/packages/evm/evmtest/wiki-how-tos/GetBalance.bin +++ /dev/null @@ -1 +0,0 @@ -608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea26469706673582212202c9d1af4136de267ede721d5e5ea147744597e332cd762811459a05c0013200264736f6c63430008140033 \ No newline at end of file diff --git a/packages/evm/evmtest/wiki-how-tos/GetBalance.abi b/packages/evm/evmtest/wiki_how_tos/GetBalance.abi similarity index 100% rename from packages/evm/evmtest/wiki-how-tos/GetBalance.abi rename to packages/evm/evmtest/wiki_how_tos/GetBalance.abi diff --git a/packages/evm/evmtest/wiki_how_tos/GetBalance.bin b/packages/evm/evmtest/wiki_how_tos/GetBalance.bin new file mode 100644 index 0000000000..a1349b6c02 --- /dev/null +++ b/packages/evm/evmtest/wiki_how_tos/GetBalance.bin @@ -0,0 +1 @@ +6080604052348015600e575f80fd5b50610ab28061001c5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107c2565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d9190610882565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108d5565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd919061090f565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107c2565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c292919061094f565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108d5565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf380057581604051610332919061090f565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107c2565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109cc565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107c2565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d99190610882565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a29565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a63565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b8281835e5f83830152505050565b5f61071161070c846105f6565b6105dc565b90508281526020810184848401111561072d5761072c61056a565b5b6107388482856106f1565b509392505050565b5f82601f83011261075457610753610566565b5b81516107648482602086016106ff565b91505092915050565b5f60208284031215610782576107816106e9565b5b61078c60206105dc565b90505f82015167ffffffffffffffff8111156107ab576107aa6106ed565b5b6107b784828501610740565b5f8301525092915050565b5f602082840312156107d7576107d661055e565b5b5f82015167ffffffffffffffff8111156107f4576107f3610562565b5b6108008482850161076d565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61082d82610809565b6108378185610813565b93506108478185602086016106f1565b6108508161056e565b840191505092915050565b5f602083015f8301518482035f8601526108758282610823565b9150508091505092915050565b5f6020820190508181035f83015261089a818461085b565b905092915050565b5f819050919050565b6108b4816108a2565b81146108be575f80fd5b50565b5f815190506108cf816108ab565b92915050565b5f602082840312156108ea576108e961055e565b5b5f6108f7848285016108c1565b91505092915050565b610909816108a2565b82525050565b5f6020820190506109225f830184610900565b92915050565b5f602083015f8301518482035f8601526109428282610823565b9150508091505092915050565b5f6040820190508181035f8301526109678185610928565b9050818103602083015261097b818461085b565b90509392505050565b5f82825260208201905092915050565b5f61099e82610809565b6109a88185610984565b93506109b88185602086016106f1565b6109c18161056e565b840191505092915050565b5f6020820190508181035f8301526109e48184610994565b905092915050565b5f67ffffffffffffffff82169050919050565b610a08816109ec565b8114610a12575f80fd5b50565b5f81519050610a23816109ff565b92915050565b5f60208284031215610a3e57610a3d61055e565b5b5f610a4b84828501610a15565b91505092915050565b610a5d816109ec565b82525050565b5f602082019050610a765f830184610a54565b9291505056fea26469706673582212201305cd24dc5a8f09ab0f20f7149275842101d3e9bbb235941608cb65e3574c9864736f6c634300081a0033 \ No newline at end of file diff --git a/packages/evm/evmtest/wiki-how-tos/GetBalance.sol b/packages/evm/evmtest/wiki_how_tos/GetBalance.sol similarity index 100% rename from packages/evm/evmtest/wiki-how-tos/GetBalance.sol rename to packages/evm/evmtest/wiki_how_tos/GetBalance.sol diff --git a/packages/evm/evmtest/wiki-how-tos/how_tos_test.go b/packages/evm/evmtest/wiki_how_tos/how_tos_test.go similarity index 99% rename from packages/evm/evmtest/wiki-how-tos/how_tos_test.go rename to packages/evm/evmtest/wiki_how_tos/how_tos_test.go index 26f1ada071..2d0186b217 100644 --- a/packages/evm/evmtest/wiki-how-tos/how_tos_test.go +++ b/packages/evm/evmtest/wiki_how_tos/how_tos_test.go @@ -1,4 +1,4 @@ -package wikihowtos_test +package wiki_how_tos_test import ( _ "embed"