diff --git a/packages/evm/evmtest/wiki_how_tos/GetAllowance.abi b/packages/evm/evmtest/wiki_how_tos/GetAllowance.abi new file mode 100644 index 0000000000..b94251c1d6 --- /dev/null +++ b/packages/evm/evmtest/wiki_how_tos/GetAllowance.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"components":[{"internalType":"uint64","name":"baseTokens","type":"uint64"},{"components":[{"components":[{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct NativeTokenID","name":"ID","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct NativeToken[]","name":"nativeTokens","type":"tuple[]"},{"internalType":"NFTID[]","name":"nfts","type":"bytes32[]"}],"indexed":false,"internalType":"struct ISCAssets","name":"assets","type":"tuple"}],"name":"AllowanceFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getAllowanceFrom","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/packages/evm/evmtest/wiki_how_tos/GetAllowance.bin b/packages/evm/evmtest/wiki_how_tos/GetAllowance.bin new file mode 100644 index 0000000000..9718a0009e --- /dev/null +++ b/packages/evm/evmtest/wiki_how_tos/GetAllowance.bin @@ -0,0 +1 @@ +6080604052348015600e575f80fd5b506109f98061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063a714b58d1461002d575b5f80fd5b61004760048036038101906100429190610181565b610049565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663a714b58d836040518263ffffffff1660e01b815260040161009791906101bb565b5f60405180830381865afa1580156100b1573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906100d991906106b4565b90507f7a438b187c47d60a258383c81f7dd0310ae6ce502b157c8c794e7647b1d391658160405161010a91906109a3565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61015082610127565b9050919050565b61016081610146565b811461016a575f80fd5b50565b5f8135905061017b81610157565b92915050565b5f602082840312156101965761019561011f565b5b5f6101a38482850161016d565b91505092915050565b6101b581610146565b82525050565b5f6020820190506101ce5f8301846101ac565b92915050565b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61021e826101d8565b810181811067ffffffffffffffff8211171561023d5761023c6101e8565b5b80604052505050565b5f61024f610116565b905061025b8282610215565b919050565b5f80fd5b5f67ffffffffffffffff82169050919050565b61028081610264565b811461028a575f80fd5b50565b5f8151905061029b81610277565b92915050565b5f80fd5b5f67ffffffffffffffff8211156102bf576102be6101e8565b5b602082029050602081019050919050565b5f80fd5b5f80fd5b5f67ffffffffffffffff8211156102f2576102f16101e8565b5b6102fb826101d8565b9050602081019050919050565b8281835e5f83830152505050565b5f610328610323846102d8565b610246565b905082815260208101848484011115610344576103436102d4565b5b61034f848285610308565b509392505050565b5f82601f83011261036b5761036a6102a1565b5b815161037b848260208601610316565b91505092915050565b5f60208284031215610399576103986101d4565b5b6103a36020610246565b90505f82015167ffffffffffffffff8111156103c2576103c1610260565b5b6103ce84828501610357565b5f8301525092915050565b5f819050919050565b6103eb816103d9565b81146103f5575f80fd5b50565b5f81519050610406816103e2565b92915050565b5f60408284031215610421576104206101d4565b5b61042b6040610246565b90505f82015167ffffffffffffffff81111561044a57610449610260565b5b61045684828501610384565b5f830152506020610469848285016103f8565b60208301525092915050565b5f610487610482846102a5565b610246565b905080838252602082019050602084028301858111156104aa576104a96102d0565b5b835b818110156104f157805167ffffffffffffffff8111156104cf576104ce6102a1565b5b8086016104dc898261040c565b855260208501945050506020810190506104ac565b5050509392505050565b5f82601f83011261050f5761050e6102a1565b5b815161051f848260208601610475565b91505092915050565b5f67ffffffffffffffff821115610542576105416101e8565b5b602082029050602081019050919050565b5f819050919050565b61056581610553565b811461056f575f80fd5b50565b5f815190506105808161055c565b92915050565b5f61059861059384610528565b610246565b905080838252602082019050602084028301858111156105bb576105ba6102d0565b5b835b818110156105e457806105d08882610572565b8452602084019350506020810190506105bd565b5050509392505050565b5f82601f830112610602576106016102a1565b5b8151610612848260208601610586565b91505092915050565b5f606082840312156106305761062f6101d4565b5b61063a6060610246565b90505f6106498482850161028d565b5f83015250602082015167ffffffffffffffff81111561066c5761066b610260565b5b610678848285016104fb565b602083015250604082015167ffffffffffffffff81111561069c5761069b610260565b5b6106a8848285016105ee565b60408301525092915050565b5f602082840312156106c9576106c861011f565b5b5f82015167ffffffffffffffff8111156106e6576106e5610123565b5b6106f28482850161061b565b91505092915050565b61070481610264565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f81519050919050565b5f82825260208201905092915050565b5f61075782610733565b610761818561073d565b9350610771818560208601610308565b61077a816101d8565b840191505092915050565b5f602083015f8301518482035f86015261079f828261074d565b9150508091505092915050565b6107b5816103d9565b82525050565b5f604083015f8301518482035f8601526107d58282610785565b91505060208301516107ea60208601826107ac565b508091505092915050565b5f61080083836107bb565b905092915050565b5f602082019050919050565b5f61081e8261070a565b6108288185610714565b93508360208202850161083a85610724565b805f5b85811015610875578484038952815161085685826107f5565b945061086183610808565b925060208a0199505060018101905061083d565b50829750879550505050505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f6108ba82610553565b9050919050565b6108ca816108b0565b82525050565b5f6108db83836108c1565b60208301905092915050565b5f602082019050919050565b5f6108fd82610887565b6109078185610891565b9350610912836108a1565b805f5b8381101561094257815161092988826108d0565b9750610934836108e7565b925050600181019050610915565b5085935050505092915050565b5f606083015f8301516109645f8601826106fb565b506020830151848203602086015261097c8282610814565b9150506040830151848203604086015261099682826108f3565b9150508091505092915050565b5f6020820190508181035f8301526109bb818461094f565b90509291505056fea2646970667358221220c2e5c9d52ccee69d8dacae7a9b441fb13df7955cf2336495a5d6c150881ce6bf64736f6c63430008190033 \ No newline at end of file diff --git a/packages/evm/evmtest/wiki_how_tos/GetAllowance.sol b/packages/evm/evmtest/wiki_how_tos/GetAllowance.sol new file mode 100644 index 0000000000..d43d088fb7 --- /dev/null +++ b/packages/evm/evmtest/wiki_how_tos/GetAllowance.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "@iscmagic/ISC.sol"; + +contract GetAllowance { + event AllowanceFrom(ISCAssets assets); + + function getAllowanceFrom(address _address) public { + ISCAssets memory assets = ISC.sandbox.getAllowanceFrom(_address); + emit AllowanceFrom(assets); + } +} diff --git a/packages/evm/evmtest/wiki_how_tos/get_allowance_test.go b/packages/evm/evmtest/wiki_how_tos/get_allowance_test.go new file mode 100644 index 0000000000..7c5cbc6a9a --- /dev/null +++ b/packages/evm/evmtest/wiki_how_tos/get_allowance_test.go @@ -0,0 +1,35 @@ +package wiki_how_tos_test + +import ( + _ "embed" + "strings" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/assert" + + "github.com/iotaledger/wasp/packages/solo" + "github.com/iotaledger/wasp/packages/vm/core/evm/evmtest" +) + +// compile the solidity contract +//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../../vm/core/evm/iscmagic` GetAllowance.sol -o ." + +var ( + //go:embed GetAllowance.abi + GetAllowanceContractABI string + //go:embed GetAllowance.bin + GetAllowanceContractBytecodeHex string + GetAllowanceContractBytecode = common.FromHex(strings.TrimSpace(GetAllowanceContractBytecodeHex)) +) + +func TestGetAllowance(t *testing.T) { + env := evmtest.InitEVMWithSolo(t, solo.New(t), true) + privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() + + instance := env.DeployContract(privateKey, GetAllowanceContractABI, GetAllowanceContractBytecode) + value, err := instance.CallFn(nil, "getAllowanceFrom", deployer) + assert.Nil(t, err) + + t.Log("value:", value) +}