From 35013e33c9e37687f7c736f29e4d5c225a8f84e1 Mon Sep 17 00:00:00 2001 From: Francisco de Borja Aranda Castillejo Date: Wed, 25 Sep 2024 09:56:53 +0200 Subject: [PATCH] test: add e2e through contract complete --- cmd/zetae2e/local/local.go | 1 + e2e/contracts/testbank/TestBank.bin | 2 +- e2e/contracts/testbank/TestBank.go | 2 +- e2e/contracts/testbank/TestBank.json | 2 +- e2e/contracts/testbank/TestBank.sol | 12 +- e2e/e2etests/test_precompiles_bank.go | 8 +- .../test_precompiles_bank_through_contract.go | 164 +++++++++++++++--- 7 files changed, 150 insertions(+), 41 deletions(-) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 33d82d1ae8..ced848aadc 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -324,6 +324,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { e2etests.TestPrecompilesStakingThroughContractName, e2etests.TestPrecompilesBankName, e2etests.TestPrecompilesBankFailName, + e2etests.TestPrecompilesBankThroughContractName, } } diff --git a/e2e/contracts/testbank/TestBank.bin b/e2e/contracts/testbank/TestBank.bin index f3a5f07a0e..fc832db5b6 100644 --- a/e2e/contracts/testbank/TestBank.bin +++ b/e2e/contracts/testbank/TestBank.bin @@ -1 +1 @@ -60a060405260675f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550348015604e575f80fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106826100a85f395f818160f7015281816101f701526102f701526106825ff3fe608060405260043610610037575f3560e01c806347e7ef2414610040578063f3fef3a31461007c578063f7888aec146100b85761003e565b3661003e57005b005b34801561004b575f80fd5b5061006660048036038101906100619190610484565b6100f4565b60405161007391906104dc565b60405180910390f35b348015610087575f80fd5b506100a2600480360381019061009d9190610484565b6101f4565b6040516100af91906104dc565b60405180910390f35b3480156100c3575f80fd5b506100de60048036038101906100d991906104f5565b6102f4565b6040516100eb9190610542565b60405180910390f35b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461014c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2485856040518363ffffffff1660e01b81526004016101a892919061056a565b6020604051808303815f875af11580156101c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101e891906105bb565b90508091505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461024c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a385856040518363ffffffff1660e01b81526004016102a892919061056a565b6020604051808303815f875af11580156102c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102e891906105bb565b90508091505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461034c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec85856040518363ffffffff1660e01b81526004016103a89291906105e6565b602060405180830381865afa1580156103c3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103e79190610621565b90508091505092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610420826103f7565b9050919050565b61043081610416565b811461043a575f80fd5b50565b5f8135905061044b81610427565b92915050565b5f819050919050565b61046381610451565b811461046d575f80fd5b50565b5f8135905061047e8161045a565b92915050565b5f806040838503121561049a576104996103f3565b5b5f6104a78582860161043d565b92505060206104b885828601610470565b9150509250929050565b5f8115159050919050565b6104d6816104c2565b82525050565b5f6020820190506104ef5f8301846104cd565b92915050565b5f806040838503121561050b5761050a6103f3565b5b5f6105188582860161043d565b92505060206105298582860161043d565b9150509250929050565b61053c81610451565b82525050565b5f6020820190506105555f830184610533565b92915050565b61056481610416565b82525050565b5f60408201905061057d5f83018561055b565b61058a6020830184610533565b9392505050565b61059a816104c2565b81146105a4575f80fd5b50565b5f815190506105b581610591565b92915050565b5f602082840312156105d0576105cf6103f3565b5b5f6105dd848285016105a7565b91505092915050565b5f6040820190506105f95f83018561055b565b610606602083018461055b565b9392505050565b5f8151905061061b8161045a565b92915050565b5f60208284031215610636576106356103f3565b5b5f6106438482850161060d565b9150509291505056fea264697066735822122058606fa72b81a1490986349908a18577e434b840b15c1299c0a4ae455e29088864736f6c634300081a0033 +60a060405260676000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561005157600080fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106a16100ae6000396000818160fc015281816101fc01526102fc01526106a16000f3fe6080604052600436106100385760003560e01c806347e7ef2414610041578063f3fef3a31461007e578063f7888aec146100bb5761003f565b3661003f57005b005b34801561004d57600080fd5b506100686004803603810190610063919061048f565b6100f8565b60405161007591906104ea565b60405180910390f35b34801561008a57600080fd5b506100a560048036038101906100a0919061048f565b6101f8565b6040516100b291906104ea565b60405180910390f35b3480156100c757600080fd5b506100e260048036038101906100dd9190610505565b6102f8565b6040516100ef9190610554565b60405180910390f35b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461015257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2484846040518363ffffffff1660e01b81526004016101ad92919061057e565b6020604051808303816000875af11580156101cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461025257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a384846040518363ffffffff1660e01b81526004016102ad92919061057e565b6020604051808303816000875af11580156102cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461035257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec84846040518363ffffffff1660e01b81526004016103ad929190610600565b602060405180830381865afa1580156103ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ee919061063e565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610426826103fb565b9050919050565b6104368161041b565b811461044157600080fd5b50565b6000813590506104538161042d565b92915050565b6000819050919050565b61046c81610459565b811461047757600080fd5b50565b60008135905061048981610463565b92915050565b600080604083850312156104a6576104a56103f6565b5b60006104b485828601610444565b92505060206104c58582860161047a565b9150509250929050565b60008115159050919050565b6104e4816104cf565b82525050565b60006020820190506104ff60008301846104db565b92915050565b6000806040838503121561051c5761051b6103f6565b5b600061052a85828601610444565b925050602061053b85828601610444565b9150509250929050565b61054e81610459565b82525050565b60006020820190506105696000830184610545565b92915050565b6105788161041b565b82525050565b6000604082019050610593600083018561056f565b6105a06020830184610545565b9392505050565b6105b0816104cf565b81146105bb57600080fd5b50565b6000815190506105cd816105a7565b92915050565b6000602082840312156105e9576105e86103f6565b5b60006105f7848285016105be565b91505092915050565b6000604082019050610615600083018561056f565b610622602083018461056f565b9392505050565b60008151905061063881610463565b92915050565b600060208284031215610654576106536103f6565b5b600061066284828501610629565b9150509291505056fea2646970667358221220c0c585590967d576c91dec72feb553b8a6186d045ddc558ecc1de043c068bcb764736f6c634300080a0033 diff --git a/e2e/contracts/testbank/TestBank.go b/e2e/contracts/testbank/TestBank.go index 0fa4357f0d..c6533c8865 100644 --- a/e2e/contracts/testbank/TestBank.go +++ b/e2e/contracts/testbank/TestBank.go @@ -32,7 +32,7 @@ var ( // TestBankMetaData contains all meta data concerning the TestBank contract. var TestBankMetaData = &bind.MetaData{ ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"zrc20\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"zrc20\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"deposit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"zrc20\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}]", - Bin: "0x60a060405260675f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550348015604e575f80fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106826100a85f395f818160f7015281816101f701526102f701526106825ff3fe608060405260043610610037575f3560e01c806347e7ef2414610040578063f3fef3a31461007c578063f7888aec146100b85761003e565b3661003e57005b005b34801561004b575f80fd5b5061006660048036038101906100619190610484565b6100f4565b60405161007391906104dc565b60405180910390f35b348015610087575f80fd5b506100a2600480360381019061009d9190610484565b6101f4565b6040516100af91906104dc565b60405180910390f35b3480156100c3575f80fd5b506100de60048036038101906100d991906104f5565b6102f4565b6040516100eb9190610542565b60405180910390f35b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461014c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2485856040518363ffffffff1660e01b81526004016101a892919061056a565b6020604051808303815f875af11580156101c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101e891906105bb565b90508091505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461024c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a385856040518363ffffffff1660e01b81526004016102a892919061056a565b6020604051808303815f875af11580156102c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102e891906105bb565b90508091505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461034c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec85856040518363ffffffff1660e01b81526004016103a89291906105e6565b602060405180830381865afa1580156103c3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103e79190610621565b90508091505092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610420826103f7565b9050919050565b61043081610416565b811461043a575f80fd5b50565b5f8135905061044b81610427565b92915050565b5f819050919050565b61046381610451565b811461046d575f80fd5b50565b5f8135905061047e8161045a565b92915050565b5f806040838503121561049a576104996103f3565b5b5f6104a78582860161043d565b92505060206104b885828601610470565b9150509250929050565b5f8115159050919050565b6104d6816104c2565b82525050565b5f6020820190506104ef5f8301846104cd565b92915050565b5f806040838503121561050b5761050a6103f3565b5b5f6105188582860161043d565b92505060206105298582860161043d565b9150509250929050565b61053c81610451565b82525050565b5f6020820190506105555f830184610533565b92915050565b61056481610416565b82525050565b5f60408201905061057d5f83018561055b565b61058a6020830184610533565b9392505050565b61059a816104c2565b81146105a4575f80fd5b50565b5f815190506105b581610591565b92915050565b5f602082840312156105d0576105cf6103f3565b5b5f6105dd848285016105a7565b91505092915050565b5f6040820190506105f95f83018561055b565b610606602083018461055b565b9392505050565b5f8151905061061b8161045a565b92915050565b5f60208284031215610636576106356103f3565b5b5f6106438482850161060d565b9150509291505056fea264697066735822122058606fa72b81a1490986349908a18577e434b840b15c1299c0a4ae455e29088864736f6c634300081a0033", + Bin: "0x60a060405260676000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561005157600080fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106a16100ae6000396000818160fc015281816101fc01526102fc01526106a16000f3fe6080604052600436106100385760003560e01c806347e7ef2414610041578063f3fef3a31461007e578063f7888aec146100bb5761003f565b3661003f57005b005b34801561004d57600080fd5b506100686004803603810190610063919061048f565b6100f8565b60405161007591906104ea565b60405180910390f35b34801561008a57600080fd5b506100a560048036038101906100a0919061048f565b6101f8565b6040516100b291906104ea565b60405180910390f35b3480156100c757600080fd5b506100e260048036038101906100dd9190610505565b6102f8565b6040516100ef9190610554565b60405180910390f35b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461015257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2484846040518363ffffffff1660e01b81526004016101ad92919061057e565b6020604051808303816000875af11580156101cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461025257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a384846040518363ffffffff1660e01b81526004016102ad92919061057e565b6020604051808303816000875af11580156102cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461035257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec84846040518363ffffffff1660e01b81526004016103ad929190610600565b602060405180830381865afa1580156103ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ee919061063e565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610426826103fb565b9050919050565b6104368161041b565b811461044157600080fd5b50565b6000813590506104538161042d565b92915050565b6000819050919050565b61046c81610459565b811461047757600080fd5b50565b60008135905061048981610463565b92915050565b600080604083850312156104a6576104a56103f6565b5b60006104b485828601610444565b92505060206104c58582860161047a565b9150509250929050565b60008115159050919050565b6104e4816104cf565b82525050565b60006020820190506104ff60008301846104db565b92915050565b6000806040838503121561051c5761051b6103f6565b5b600061052a85828601610444565b925050602061053b85828601610444565b9150509250929050565b61054e81610459565b82525050565b60006020820190506105696000830184610545565b92915050565b6105788161041b565b82525050565b6000604082019050610593600083018561056f565b6105a06020830184610545565b9392505050565b6105b0816104cf565b81146105bb57600080fd5b50565b6000815190506105cd816105a7565b92915050565b6000602082840312156105e9576105e86103f6565b5b60006105f7848285016105be565b91505092915050565b6000604082019050610615600083018561056f565b610622602083018461056f565b9392505050565b60008151905061063881610463565b92915050565b600060208284031215610654576106536103f6565b5b600061066284828501610629565b9150509291505056fea2646970667358221220c0c585590967d576c91dec72feb553b8a6186d045ddc558ecc1de043c068bcb764736f6c634300080a0033", } // TestBankABI is the input ABI used to generate the binding from. diff --git a/e2e/contracts/testbank/TestBank.json b/e2e/contracts/testbank/TestBank.json index 5c665fd9a3..98b6ac1e68 100644 --- a/e2e/contracts/testbank/TestBank.json +++ b/e2e/contracts/testbank/TestBank.json @@ -86,5 +86,5 @@ "type": "receive" } ], - "bin": "60a060405260675f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550348015604e575f80fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106826100a85f395f818160f7015281816101f701526102f701526106825ff3fe608060405260043610610037575f3560e01c806347e7ef2414610040578063f3fef3a31461007c578063f7888aec146100b85761003e565b3661003e57005b005b34801561004b575f80fd5b5061006660048036038101906100619190610484565b6100f4565b60405161007391906104dc565b60405180910390f35b348015610087575f80fd5b506100a2600480360381019061009d9190610484565b6101f4565b6040516100af91906104dc565b60405180910390f35b3480156100c3575f80fd5b506100de60048036038101906100d991906104f5565b6102f4565b6040516100eb9190610542565b60405180910390f35b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461014c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2485856040518363ffffffff1660e01b81526004016101a892919061056a565b6020604051808303815f875af11580156101c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101e891906105bb565b90508091505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461024c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a385856040518363ffffffff1660e01b81526004016102a892919061056a565b6020604051808303815f875af11580156102c4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102e891906105bb565b90508091505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461034c575f80fd5b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec85856040518363ffffffff1660e01b81526004016103a89291906105e6565b602060405180830381865afa1580156103c3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103e79190610621565b90508091505092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610420826103f7565b9050919050565b61043081610416565b811461043a575f80fd5b50565b5f8135905061044b81610427565b92915050565b5f819050919050565b61046381610451565b811461046d575f80fd5b50565b5f8135905061047e8161045a565b92915050565b5f806040838503121561049a576104996103f3565b5b5f6104a78582860161043d565b92505060206104b885828601610470565b9150509250929050565b5f8115159050919050565b6104d6816104c2565b82525050565b5f6020820190506104ef5f8301846104cd565b92915050565b5f806040838503121561050b5761050a6103f3565b5b5f6105188582860161043d565b92505060206105298582860161043d565b9150509250929050565b61053c81610451565b82525050565b5f6020820190506105555f830184610533565b92915050565b61056481610416565b82525050565b5f60408201905061057d5f83018561055b565b61058a6020830184610533565b9392505050565b61059a816104c2565b81146105a4575f80fd5b50565b5f815190506105b581610591565b92915050565b5f602082840312156105d0576105cf6103f3565b5b5f6105dd848285016105a7565b91505092915050565b5f6040820190506105f95f83018561055b565b610606602083018461055b565b9392505050565b5f8151905061061b8161045a565b92915050565b5f60208284031215610636576106356103f3565b5b5f6106438482850161060d565b9150509291505056fea264697066735822122058606fa72b81a1490986349908a18577e434b840b15c1299c0a4ae455e29088864736f6c634300081a0033" + "bin": "60a060405260676000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561005157600080fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106a16100ae6000396000818160fc015281816101fc01526102fc01526106a16000f3fe6080604052600436106100385760003560e01c806347e7ef2414610041578063f3fef3a31461007e578063f7888aec146100bb5761003f565b3661003f57005b005b34801561004d57600080fd5b506100686004803603810190610063919061048f565b6100f8565b60405161007591906104ea565b60405180910390f35b34801561008a57600080fd5b506100a560048036038101906100a0919061048f565b6101f8565b6040516100b291906104ea565b60405180910390f35b3480156100c757600080fd5b506100e260048036038101906100dd9190610505565b6102f8565b6040516100ef9190610554565b60405180910390f35b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461015257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2484846040518363ffffffff1660e01b81526004016101ad92919061057e565b6020604051808303816000875af11580156101cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461025257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a384846040518363ffffffff1660e01b81526004016102ad92919061057e565b6020604051808303816000875af11580156102cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461035257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec84846040518363ffffffff1660e01b81526004016103ad929190610600565b602060405180830381865afa1580156103ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ee919061063e565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610426826103fb565b9050919050565b6104368161041b565b811461044157600080fd5b50565b6000813590506104538161042d565b92915050565b6000819050919050565b61046c81610459565b811461047757600080fd5b50565b60008135905061048981610463565b92915050565b600080604083850312156104a6576104a56103f6565b5b60006104b485828601610444565b92505060206104c58582860161047a565b9150509250929050565b60008115159050919050565b6104e4816104cf565b82525050565b60006020820190506104ff60008301846104db565b92915050565b6000806040838503121561051c5761051b6103f6565b5b600061052a85828601610444565b925050602061053b85828601610444565b9150509250929050565b61054e81610459565b82525050565b60006020820190506105696000830184610545565b92915050565b6105788161041b565b82525050565b6000604082019050610593600083018561056f565b6105a06020830184610545565b9392505050565b6105b0816104cf565b81146105bb57600080fd5b50565b6000815190506105cd816105a7565b92915050565b6000602082840312156105e9576105e86103f6565b5b60006105f7848285016105be565b91505092915050565b6000604082019050610615600083018561056f565b610622602083018461056f565b9392505050565b60008151905061063881610463565b92915050565b600060208284031215610654576106536103f6565b5b600061066284828501610629565b9150509291505056fea2646970667358221220c0c585590967d576c91dec72feb553b8a6186d045ddc558ecc1de043c068bcb764736f6c634300080a0033" } diff --git a/e2e/contracts/testbank/TestBank.sol b/e2e/contracts/testbank/TestBank.sol index ca6ee35d11..715e8b4f71 100644 --- a/e2e/contracts/testbank/TestBank.sol +++ b/e2e/contracts/testbank/TestBank.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.26; +pragma solidity 0.8.10; // @dev Interface for IBank contract interface IBank { @@ -22,6 +22,7 @@ interface IBank { // @dev Call IBank contract functions contract TestBank { IBank bank = IBank(0x0000000000000000000000000000000000000067); + address immutable owner; constructor() { @@ -37,24 +38,21 @@ contract TestBank { address zrc20, uint256 amount ) external onlyOwner returns (bool) { - bool success = bank.deposit(zrc20, amount); - return success; + return bank.deposit(zrc20, amount); } function withdraw( address zrc20, uint256 amount ) external onlyOwner returns (bool) { - bool success = bank.withdraw(zrc20, amount); - return success; + return bank.withdraw(zrc20, amount); } function balanceOf( address zrc20, address user ) external view onlyOwner returns (uint256) { - uint256 balance = bank.balanceOf(zrc20, user); - return balance; + return bank.balanceOf(zrc20, user); } fallback() external payable {} diff --git a/e2e/e2etests/test_precompiles_bank.go b/e2e/e2etests/test_precompiles_bank.go index 1e78212355..5aa7a00f95 100644 --- a/e2e/e2etests/test_precompiles_bank.go +++ b/e2e/e2etests/test_precompiles_bank.go @@ -116,10 +116,10 @@ func TestPrecompilesBank(r *runner.E2ERunner, args []string) { // Check the withdraw event. eventWithdraw, err := bankContract.ParseWithdraw(*receipt.Logs[0]) - require.NoError(r, err, "Parse Deposit event") - require.Equal(r, r.EVMAddress(), eventWithdraw.Zrc20Withdrawer, "Deposit event token should be r.EVMAddress()") - require.Equal(r, r.ERC20ZRC20Addr, eventWithdraw.Zrc20Token, "Deposit event token should be ERC20ZRC20Addr") - require.Equal(r, depositAmount, eventWithdraw.Amount, "Deposit event amount should be 500") + require.NoError(r, err, "Parse Withdraw event") + require.Equal(r, r.EVMAddress(), eventWithdraw.Zrc20Withdrawer, "Withdrawer should be r.EVMAddress()") + require.Equal(r, r.ERC20ZRC20Addr, eventWithdraw.Zrc20Token, "Withdraw event token should be ERC20ZRC20Addr") + require.Equal(r, depositAmount, eventWithdraw.Amount, "Withdraw event amount should be 500") // Spender: cosmos coin balance should be 0 at this point. cosmosBalance, err = bankContract.BalanceOf(&bind.CallOpts{Context: r.Ctx}, r.ERC20ZRC20Addr, spender) diff --git a/e2e/e2etests/test_precompiles_bank_through_contract.go b/e2e/e2etests/test_precompiles_bank_through_contract.go index 97c69d69dc..2226927761 100644 --- a/e2e/e2etests/test_precompiles_bank_through_contract.go +++ b/e2e/e2etests/test_precompiles_bank_through_contract.go @@ -1,55 +1,142 @@ package e2etests import ( - "fmt" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" "github.com/zeta-chain/node/e2e/contracts/testbank" "github.com/zeta-chain/node/e2e/runner" "github.com/zeta-chain/node/e2e/utils" + "github.com/zeta-chain/node/precompiles/bank" ) func TestPrecompilesBankThroughContract(r *runner.E2ERunner, args []string) { require.Len(r, args, 0, "No arguments expected") - // Increase the gasLimit. It's required because of the gas consumed by precompiled functions. + spender := r.EVMAddress() + zrc20Address := r.ERC20ZRC20Addr + oneThousand := big.NewInt(1e3) + oneThousandOne := big.NewInt(1001) + fiveHundred := big.NewInt(500) + fiveHundredOne := big.NewInt(501) + + // Get ERC20ZRC20. + txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), oneThousand, []byte{}) + utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) + + bankPrecompileCaller, err := bank.NewIBank(bank.ContractAddress, r.ZEVMClient) + require.NoError(r, err, "Failed to create bank precompile caller") + + // Deploy the TestBank. Ensure the transaction is successful. + _, tx, testBank, err := testbank.DeployTestBank(r.ZEVMAuth, r.ZEVMClient) + require.NoError(r, err) + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + utils.RequireTxSuccessful(r, receipt, "Deployment of TestBank contract failed") + previousGasLimit := r.ZEVMAuth.GasLimit r.ZEVMAuth.GasLimit = 10_000_000 defer func() { r.ZEVMAuth.GasLimit = previousGasLimit - // // Reset the allowance to 0; this is needed when running upgrade tests where - // // this test runs twice. - // tx, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, bank.ContractAddress, big.NewInt(0)) - // require.NoError(r, err) - // receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - // utils.RequireTxSuccessful(r, receipt, "Resetting allowance failed") + // Reset the allowance to 0; this is needed when running upgrade tests where this test runs twice. + approveAllowance(r, bank.ContractAddress, big.NewInt(0)) }() - spender := r.EVMAddress() - zrc20Address := r.ERC20ZRC20Addr - totalAmount := big.NewInt(1e3) - fmt.Printf("DEBUG: spender %v\n", spender) - fmt.Printf("DEBUG: zrc20Address %v\n", zrc20Address) + // Check initial balances. + balanceShouldBe(r, 0, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 1000, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 0, checkZRC20Balance(r, bank.ContractAddress)) - // Get ERC20ZRC20. - txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), totalAmount, []byte{}) - utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) + // Deposit without previous alllowance should fail. + receipt = depositThroughTestBank(r, testBank, zrc20Address, oneThousand) + utils.RequiredTxFailed(r, receipt, "Deposit ERC20ZRC20 without allowance should fail") - testBankAddr, tx, testBank, err := testbank.DeployTestBank(r.ZEVMAuth, r.ZEVMClient) - require.NoError(r, err) - utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - fmt.Printf("DEBUG: testBankAddr %v\n", testBankAddr) + // Check balances, should be the same. + balanceShouldBe(r, 0, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 1000, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 0, checkZRC20Balance(r, bank.ContractAddress)) + + // Allow 500 ZRC20 to bank precompile. + approveAllowance(r, bank.ContractAddress, fiveHundred) + + // Deposit 501 ERC20ZRC20 tokens to the bank contract, through TestBank. + // It's higher than allowance but lower than balance, should fail. + receipt = depositThroughTestBank(r, testBank, zrc20Address, fiveHundredOne) + utils.RequiredTxFailed(r, receipt, "Depositting an amount higher than allowed should fail") + + // Balances shouldn't change. + balanceShouldBe(r, 0, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 1000, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 0, checkZRC20Balance(r, bank.ContractAddress)) + + // Allow 1000 ZRC20 to bank precompile. + approveAllowance(r, bank.ContractAddress, oneThousand) + + // Deposit 1001 ERC20ZRC20 tokens to the bank contract. + // It's higher than spender balance but within approved allowance, should fail. + receipt = depositThroughTestBank(r, testBank, zrc20Address, oneThousandOne) + utils.RequiredTxFailed(r, receipt, "Depositting an amount higher than balance should fail") + + // Balances shouldn't change. + balanceShouldBe(r, 0, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 1000, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 0, checkZRC20Balance(r, bank.ContractAddress)) - // Initial cosmos balance should be 0. - balance, err := testBank.BalanceOf(&bind.CallOpts{Context: r.Ctx}, zrc20Address, spender) + // Deposit 500 ERC20ZRC20 tokens to the bank contract, it's within allowance and balance. Should pass. + receipt = depositThroughTestBank(r, testBank, zrc20Address, fiveHundred) + utils.RequireTxSuccessful(r, receipt, "Depositting a correct amount should pass") + + // Balances should be transferred. Bank now locks 500 ZRC20 tokens. + balanceShouldBe(r, 500, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 500, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 500, checkZRC20Balance(r, bank.ContractAddress)) + + // Check the deposit event. + eventDeposit, err := bankPrecompileCaller.ParseDeposit(*receipt.Logs[0]) + require.NoError(r, err, "Parse Deposit event") + require.Equal(r, r.EVMAddress(), eventDeposit.Zrc20Depositor, "Deposit event token should be r.EVMAddress()") + require.Equal(r, r.ERC20ZRC20Addr, eventDeposit.Zrc20Token, "Deposit event token should be ERC20ZRC20Addr") + require.Equal(r, fiveHundred, eventDeposit.Amount, "Deposit event amount should be 500") + + // Should faild to withdraw more than cosmos balance. + receipt = withdrawThroughTestBank(r, testBank, zrc20Address, fiveHundredOne) + utils.RequiredTxFailed(r, receipt, "Withdrawing an amount higher than balance should fail") + + // Balances shouldn't change. + balanceShouldBe(r, 500, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 500, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 500, checkZRC20Balance(r, bank.ContractAddress)) + + // Try to withdraw 500 ERC20ZRC20 tokens. Should pass. + receipt = withdrawThroughTestBank(r, testBank, zrc20Address, fiveHundred) + utils.RequireTxSuccessful(r, receipt, "Withdraw correct amount should pass") + + // Balances should be reverted to initial state. + balanceShouldBe(r, 0, checkCosmosBalance(r, testBank, zrc20Address, spender)) + balanceShouldBe(r, 1000, checkZRC20Balance(r, spender)) + balanceShouldBe(r, 0, checkZRC20Balance(r, bank.ContractAddress)) + + // Check the withdraw event. + eventWithdraw, err := bankPrecompileCaller.ParseWithdraw(*receipt.Logs[0]) + require.NoError(r, err, "Parse Withdraw event") + require.Equal(r, r.EVMAddress(), eventWithdraw.Zrc20Withdrawer, "Withdrawer should be r.EVMAddress()") + require.Equal(r, r.ERC20ZRC20Addr, eventWithdraw.Zrc20Token, "Withdraw event token should be ERC20ZRC20Addr") + require.Equal(r, fiveHundred, eventWithdraw.Amount, "Withdraw event amount should be 500") +} + +func approveAllowance(r *runner.E2ERunner, target common.Address, amount *big.Int) { + tx, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, target, amount) require.NoError(r, err) - require.Equal(r, int64(0), balance.Int64()) - fmt.Printf("DEBUG: initial balance %v\n", balance) + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + utils.RequireTxSuccessful(r, receipt, "Approve ERC20ZRC20 allowance tx failed") +} + +func balanceShouldBe(r *runner.E2ERunner, expected uint64, balance *big.Int) { + require.Equal(r, expected, balance.Uint64(), "Balance should be %d, got: %d", expected, balance.Uint64()) } func checkZRC20Balance(r *runner.E2ERunner, target common.Address) *big.Int { @@ -58,9 +145,32 @@ func checkZRC20Balance(r *runner.E2ERunner, target common.Address) *big.Int { return bankZRC20Balance } -func allowZRC20fromSpender(r *runner.E2ERunner, target common.Address, amount *big.Int) { - tx, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, target, amount) +func checkCosmosBalance(r *runner.E2ERunner, bank *testbank.TestBank, zrc20, target common.Address) *big.Int { + balance, err := bank.BalanceOf(&bind.CallOpts{Context: r.Ctx, From: r.ZEVMAuth.From}, zrc20, target) + require.NoError(r, err) + return balance +} + +func depositThroughTestBank( + r *runner.E2ERunner, + bank *testbank.TestBank, + zrc20Address common.Address, + amount *big.Int, +) *types.Receipt { + tx, err := bank.Deposit(r.ZEVMAuth, zrc20Address, amount) + require.NoError(r, err) + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + return receipt +} + +func withdrawThroughTestBank( + r *runner.E2ERunner, + bank *testbank.TestBank, + zrc20Address common.Address, + amount *big.Int, +) *types.Receipt { + tx, err := bank.Withdraw(r.ZEVMAuth, zrc20Address, amount) require.NoError(r, err) receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - utils.RequireTxSuccessful(r, receipt, "Approve ETHZRC20 bank allowance tx failed") + return receipt }