From f015ba18d89379a9eb3a8e746cd9db9bc56ee230 Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Mon, 17 Jul 2023 13:17:57 +0100 Subject: [PATCH] chore: engine integration tests refactoring (#777) ## Description The main goal of the PR is to replace the deprecated `near-sdk-sim` crate with the `aurora-engine-workspace` crate, which is based on [workspaces](https://github.com/near/workspaces-rs). Also, some test files have been restructured. ## Performance / NEAR gas cost considerations No changes in gas costs. --- Cargo.lock | 2465 ++++++++++------- Cargo.toml | 22 +- engine-precompiles/src/xcc.rs | 24 +- engine-tests/Cargo.toml | 5 +- engine-tests/src/benches/eth_deploy_code.rs | 9 +- engine-tests/src/benches/eth_erc20.rs | 12 +- .../src/benches/eth_standard_precompiles.rs | 10 +- engine-tests/src/benches/eth_transfer.rs | 4 +- engine-tests/src/benches/nft_pagination.rs | 14 +- engine-tests/src/benches/uniswap.rs | 10 +- engine-tests/src/lib.rs | 4 +- engine-tests/src/prelude.rs | 1 - engine-tests/src/tests/access_lists.rs | 67 - .../src/tests/account_id_precompiles.rs | 16 +- engine-tests/src/tests/contract_call.rs | 16 +- engine-tests/src/tests/ecrecover.rs | 7 +- engine-tests/src/tests/erc20.rs | 54 +- engine-tests/src/tests/erc20_connector.rs | 549 ++-- engine-tests/src/tests/eth_connector.rs | 2088 ++++++-------- engine-tests/src/tests/ghsa_3p69_m8gg_fwmf.rs | 10 +- engine-tests/src/tests/mod.rs | 7 +- engine-tests/src/tests/modexp.rs | 19 +- engine-tests/src/tests/multisender.rs | 44 +- engine-tests/src/tests/one_inch.rs | 34 +- .../src/tests/pausable_precompiles.rs | 16 +- engine-tests/src/tests/pause_contract.rs | 16 +- .../src/tests/prepaid_gas_precompile.rs | 12 +- .../src/tests/promise_results_precompile.rs | 22 +- engine-tests/src/tests/random.rs | 8 +- engine-tests/src/tests/repro.rs | 6 +- engine-tests/src/tests/sanity.rs | 454 ++- engine-tests/src/tests/self_destruct_state.rs | 12 +- .../src/tests/standalone/call_tracer.rs | 47 +- .../src/tests/standalone/json_snapshot.rs | 8 +- engine-tests/src/tests/standalone/storage.rs | 28 +- engine-tests/src/tests/standalone/sync.rs | 41 +- engine-tests/src/tests/standalone/tracing.rs | 20 +- .../src/tests/standard_precompiles.rs | 28 +- engine-tests/src/tests/state_migration.rs | 118 - .../src/tests/{eip1559.rs => transaction.rs} | 82 +- engine-tests/src/tests/uniswap.rs | 26 +- engine-tests/src/tests/upgrade.rs | 65 + engine-tests/src/tests/xcc.rs | 1139 ++++---- .../{test_utils => utils}/mocked_external.rs | 47 +- engine-tests/src/{test_utils => utils}/mod.rs | 36 +- .../one_inch/liquidity_protocol.rs | 44 +- .../src/{test_utils => utils}/one_inch/mod.rs | 10 +- .../src/{test_utils => utils}/rust.rs | 0 .../{test_utils => utils/solidity}/erc20.rs | 2 +- .../solidity}/exit_precompile.rs | 8 +- .../solidity.rs => utils/solidity/mod.rs} | 8 + .../{test_utils => utils/solidity}/random.rs | 4 +- .../solidity}/self_destruct.rs | 8 +- .../solidity}/standard_precompiles.rs | 2 +- .../{test_utils => utils/solidity}/uniswap.rs | 6 +- .../{test_utils => utils/solidity}/weth.rs | 2 +- .../standalone/mocks/block.rs | 0 .../standalone/mocks/mod.rs | 8 +- .../{test_utils => utils}/standalone/mod.rs | 32 +- .../standalone/storage.rs | 0 engine-tests/src/utils/workspace.rs | 131 + engine-transactions/src/legacy.rs | 2 +- engine-types/src/parameters/mod.rs | 1 + engine-types/src/parameters/xcc.rs | 28 + engine-workspace/Cargo.toml | 26 + engine-workspace/README.md | 2 + engine-workspace/src/account.rs | 51 + engine-workspace/src/contract.rs | 393 +++ engine-workspace/src/lib.rs | 164 ++ engine-workspace/src/macros.rs | 111 + engine-workspace/src/node.rs | 104 + engine-workspace/src/operation.rs | 206 ++ engine-workspace/src/result.rs | 166 ++ engine-workspace/src/transaction.rs | 83 + engine/src/connector.rs | 2 +- engine/src/lib.rs | 3 +- engine/src/state.rs | 7 +- engine/src/xcc.rs | 21 +- etc/tests/fibonacci/Cargo.toml | 2 +- etc/tests/ft-receiver/Cargo.toml | 4 +- etc/xcc-router/Cargo.lock | 699 +++-- etc/xcc-router/Cargo.toml | 2 +- 82 files changed, 5759 insertions(+), 4305 deletions(-) delete mode 100644 engine-tests/src/tests/access_lists.rs delete mode 100644 engine-tests/src/tests/state_migration.rs rename engine-tests/src/tests/{eip1559.rs => transaction.rs} (62%) create mode 100644 engine-tests/src/tests/upgrade.rs rename engine-tests/src/{test_utils => utils}/mocked_external.rs (79%) rename engine-tests/src/{test_utils => utils}/mod.rs (97%) rename engine-tests/src/{test_utils => utils}/one_inch/liquidity_protocol.rs (83%) rename engine-tests/src/{test_utils => utils}/one_inch/mod.rs (87%) rename engine-tests/src/{test_utils => utils}/rust.rs (100%) rename engine-tests/src/{test_utils => utils/solidity}/erc20.rs (99%) rename engine-tests/src/{test_utils => utils/solidity}/exit_precompile.rs (96%) rename engine-tests/src/{test_utils/solidity.rs => utils/solidity/mod.rs} (97%) rename engine-tests/src/{test_utils => utils/solidity}/random.rs (94%) rename engine-tests/src/{test_utils => utils/solidity}/self_destruct.rs (96%) rename engine-tests/src/{test_utils => utils/solidity}/standard_precompiles.rs (97%) rename engine-tests/src/{test_utils => utils/solidity}/uniswap.rs (99%) rename engine-tests/src/{test_utils => utils/solidity}/weth.rs (97%) rename engine-tests/src/{test_utils => utils}/standalone/mocks/block.rs (100%) rename engine-tests/src/{test_utils => utils}/standalone/mocks/mod.rs (95%) rename engine-tests/src/{test_utils => utils}/standalone/mod.rs (94%) rename engine-tests/src/{test_utils => utils}/standalone/storage.rs (100%) create mode 100644 engine-tests/src/utils/workspace.rs create mode 100644 engine-types/src/parameters/xcc.rs create mode 100644 engine-workspace/Cargo.toml create mode 100644 engine-workspace/README.md create mode 100644 engine-workspace/src/account.rs create mode 100644 engine-workspace/src/contract.rs create mode 100644 engine-workspace/src/lib.rs create mode 100644 engine-workspace/src/macros.rs create mode 100644 engine-workspace/src/node.rs create mode 100644 engine-workspace/src/operation.rs create mode 100644 engine-workspace/src/result.rs create mode 100644 engine-workspace/src/transaction.rs diff --git a/Cargo.lock b/Cargo.lock index f398bc7b0..67b859a8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "f728064aca1c318585bf4bb04ffcfac9e75e508ab4e8b1bd9ba5dfe04e2cbed5" dependencies = [ "actix-rt", "actix_derive", - "bitflags", + "bitflags 1.3.2", "bytes", "crossbeam-channel", "futures-core", @@ -25,30 +25,19 @@ dependencies = [ "futures-util", "log", "once_cell", - "parking_lot 0.12.1", + "parking_lot", "pin-project-lite", "smallvec", "tokio", "tokio-util 0.7.3", ] -[[package]] -name = "actix-macros" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6" -dependencies = [ - "quote", - "syn 1.0.109", -] - [[package]] name = "actix-rt" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15265b6b8e2347670eb363c47fc8c75208b4a4994b27192f345fcbe707804f3e" dependencies = [ - "actix-macros", "futures-core", "tokio", ] @@ -75,9 +64,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" dependencies = [ "gimli 0.27.3", ] @@ -222,6 +211,64 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock", + "autocfg", + "cfg-if 1.0.0", + "concurrent-queue", + "futures-lite", + "log", + "parking", + "polling", + "rustix 0.37.23", + "slab", + "socket2", + "waker-fn", +] + +[[package]] +name = "async-lock" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-process" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if 1.0.0", + "event-listener", + "futures-lite", + "rustix 0.37.23", + "signal-hook", + "windows-sys 0.48.0", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -241,20 +288,32 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] +[[package]] +name = "async-task" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" + [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] +[[package]] +name = "atomic-waker" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" + [[package]] name = "atty" version = "0.2.14" @@ -276,11 +335,11 @@ dependencies = [ "aurora-engine-test-doubles", "aurora-engine-transactions", "aurora-engine-types", - "bitflags", + "bitflags 1.3.2", "digest 0.10.7", "ethabi", "evm", - "hex", + "hex 0.4.3", "rlp", "serde", "serde_json", @@ -292,7 +351,7 @@ dependencies = [ name = "aurora-engine-modexp" version = "1.0.0" dependencies = [ - "hex", + "hex 0.4.3", "ibig", "num", ] @@ -307,7 +366,7 @@ dependencies = [ "aurora-engine-types", "ethabi", "evm", - "hex", + "hex 0.4.3", "libsecp256k1", "num", "rand 0.8.5", @@ -344,6 +403,7 @@ dependencies = [ name = "aurora-engine-tests" version = "1.0.0" dependencies = [ + "anyhow", "aurora-engine", "aurora-engine-modexp", "aurora-engine-precompiles", @@ -351,6 +411,7 @@ dependencies = [ "aurora-engine-test-doubles", "aurora-engine-transactions", "aurora-engine-types", + "aurora-engine-workspace", "borsh 0.10.3", "bstr", "byte-slice-cast", @@ -362,21 +423,21 @@ dependencies = [ "evm-gasometer", "evm-runtime", "git2", - "hex", + "hex 0.4.3", "libsecp256k1", - "near-crypto 0.16.1", - "near-primitives 0.16.1", - "near-primitives-core 0.16.1", - "near-sdk-sim", - "near-vm-errors 0.16.1", - "near-vm-logic 0.16.1", - "near-vm-runner 0.16.1", + "near-crypto 0.17.0", + "near-primitives 0.17.0", + "near-primitives-core 0.17.0", + "near-vm-errors 0.17.0", + "near-vm-logic 0.17.0", + "near-vm-runner", "rand 0.8.5", "rlp", "serde", "serde_json", "sha3", "tempfile", + "tokio", "walrus", ] @@ -388,7 +449,7 @@ dependencies = [ "aurora-engine-sdk", "aurora-engine-types", "evm", - "hex", + "hex 0.4.3", "rlp", "serde", ] @@ -400,7 +461,7 @@ dependencies = [ "base64 0.21.2", "borsh 0.10.3", "borsh 0.9.3", - "hex", + "hex 0.4.3", "primitive-types 0.12.1", "rand 0.8.5", "rlp", @@ -408,6 +469,22 @@ dependencies = [ "serde_json", ] +[[package]] +name = "aurora-engine-workspace" +version = "0.1.0" +dependencies = [ + "anyhow", + "aurora-engine-types", + "hex 0.4.3", + "lazy_static", + "near-sdk", + "near-units", + "serde", + "serde_json", + "tokio", + "workspaces", +] + [[package]] name = "auto_impl" version = "1.1.0" @@ -428,19 +505,25 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" dependencies = [ - "addr2line 0.19.0", + "addr2line 0.20.0", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.30.4", + "object 0.31.1", "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" + [[package]] name = "base64" version = "0.13.1" @@ -453,6 +536,23 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +[[package]] +name = "binary-install" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5bc5f8c50dd6a80d0b303ddab79f42ddcb52fd43d68107ecf622c551fd4cd4" +dependencies = [ + "curl", + "dirs 1.0.5", + "failure", + "flate2", + "hex 0.3.2", + "is_executable", + "siphasher 0.2.3", + "tar", + "zip", +] + [[package]] name = "bincode" version = "1.3.3" @@ -468,7 +568,7 @@ version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "lazy_static", @@ -488,6 +588,24 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + +[[package]] +name = "bitvec" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848" +dependencies = [ + "funty 1.1.0", + "radium 0.6.2", + "tap", + "wyz 0.2.0", +] + [[package]] name = "bitvec" version = "1.0.1" @@ -495,9 +613,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty 2.0.0", - "radium", + "radium 0.7.0", "tap", - "wyz", + "wyz 0.5.1", ] [[package]] @@ -512,18 +630,14 @@ dependencies = [ ] [[package]] -name = "blake3" -version = "0.3.8" +name = "blake2b_simd" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" dependencies = [ "arrayref", "arrayvec 0.5.2", - "cc", - "cfg-if 0.1.10", "constant_time_eq", - "crypto-mac", - "digest 0.9.0", ] [[package]] @@ -532,7 +646,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -541,7 +655,22 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.7", + "generic-array", +] + +[[package]] +name = "blocking" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "log", ] [[package]] @@ -642,13 +771,12 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5" +checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" dependencies = [ "memchr", - "once_cell", - "regex-automata", + "regex-automata 0.3.2", "serde", ] @@ -707,6 +835,16 @@ dependencies = [ "serde", ] +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + [[package]] name = "bzip2-sys" version = "0.1.11+1.0.8" @@ -813,7 +951,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -829,58 +967,27 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "atty", - "bitflags", - "clap_derive 3.2.25", - "clap_lex 0.2.4", - "indexmap 1.9.3", - "once_cell", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap" -version = "4.3.9" +version = "4.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bba77a07e4489fb41bd90e8d4201c3eb246b3c2c9ea2ba0bddd6c1d1df87db7d" +checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" dependencies = [ "clap_builder", - "clap_derive 4.3.2", + "clap_derive", "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.9" +version = "4.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9b4a88bb4bc35d3d6f65a21b0f0bafe9c894fa00978de242c555ec28bea1c0" +checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" dependencies = [ "anstream", "anstyle", - "bitflags", - "clap_lex 0.5.0", + "clap_lex", "strsim", ] -[[package]] -name = "clap_derive" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" -dependencies = [ - "heck 0.4.1", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "clap_derive" version = "4.3.2" @@ -890,16 +997,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.22", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", + "syn 2.0.25", ] [[package]] @@ -908,21 +1006,21 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -935,6 +1033,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -952,9 +1060,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -986,7 +1094,7 @@ dependencies = [ "log", "regalloc2", "smallvec", - "target-lexicon 0.12.8", + "target-lexicon", ] [[package]] @@ -1036,7 +1144,7 @@ dependencies = [ "cranelift-codegen", "log", "smallvec", - "target-lexicon 0.12.8", + "target-lexicon", ] [[package]] @@ -1053,7 +1161,7 @@ checksum = "ba392fd53b1bf6d45bf1d97f7e13bb8ba8424f19d66d80e60a0d594c2bb2636e" dependencies = [ "cranelift-codegen", "libc", - "target-lexicon 0.12.8", + "target-lexicon", ] [[package]] @@ -1090,7 +1198,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.3.9", + "clap", "criterion-plot", "is-terminal", "itertools", @@ -1117,20 +1225,6 @@ dependencies = [ "itertools", ] -[[package]] -name = "crossbeam" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-epoch", - "crossbeam-queue", - "crossbeam-utils", -] - [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -1165,16 +1259,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.16" @@ -1196,7 +1280,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.7", + "generic-array", "typenum", ] @@ -1206,10 +1290,40 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.7", + "generic-array", "subtle", ] +[[package]] +name = "curl" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi", +] + +[[package]] +name = "curl-sys" +version = "0.4.63+curl-8.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb0fef7046022a1e2ad67a004978f0e3cacb9e3123dc62ce768f92197b771dc" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", +] + [[package]] name = "curve25519-dalek" version = "3.2.1" @@ -1243,7 +1357,8 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.22", + "strsim", + "syn 2.0.25", ] [[package]] @@ -1254,7 +1369,7 @@ checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ "darling_core", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1265,7 +1380,7 @@ checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1277,26 +1392,17 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn 1.0.109", ] -[[package]] -name = "digest" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -dependencies = [ - "generic-array 0.12.4", -] - [[package]] name = "digest" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -1310,19 +1416,56 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users 0.3.5", + "winapi", +] + +[[package]] +name = "dirs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users 0.4.3", + "winapi", +] + [[package]] name = "dissimilar" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e" +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + [[package]] name = "dynasm" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "add9a102807b524ec050363f09e06f1504214b0e1c7797f64261c891022dce8b" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder", "lazy_static", "proc-macro-error", @@ -1378,12 +1521,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] -name = "elastic-array" -version = "0.11.0" +name = "encoding_rs" +version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d63720ea2bc2e1b79f7aa044d9dc0b825f9ccb6930b32120f8fb9e873aa84bc" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ - "heapsize", + "cfg-if 1.0.0", ] [[package]] @@ -1397,7 +1540,7 @@ dependencies = [ "aurora-engine-transactions", "aurora-engine-types", "evm-core", - "hex", + "hex 0.4.3", "postgres", "rocksdb", "serde", @@ -1413,28 +1556,28 @@ dependencies = [ "evm-core", "evm-gasometer", "evm-runtime", - "hex", + "hex 0.4.3", "serde", ] [[package]] name = "enum-map" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "988f0d17a0fa38291e5f41f71ea8d46a5d5497b9054d5a759fae2cbb819f2356" +checksum = "017b207acb4cc917f4c31758ed95c0bc63ddb0f358b22eb38f80a2b2a43f6b1f" dependencies = [ "enum-map-derive", ] [[package]] name = "enum-map-derive" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4da76b3b6116d758c7ba93f7ec6a35d2e2cf24feda76c6e38a375f4d5c59f2" +checksum = "8560b409800a72d2d7860f8e5f4e0b0bd22bea6a352ea2a9ce30ccdef7f16d2f" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", ] [[package]] @@ -1455,7 +1598,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1466,20 +1609,9 @@ checksum = "e48c92028aaa870e83d51c64e5d4e0b6981b360c522198c23959f219a4e1b15b" [[package]] name = "equivalent" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" - -[[package]] -name = "errno" -version = "0.2.8" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" @@ -1509,7 +1641,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" dependencies = [ "ethereum-types", - "hex", + "hex 0.4.3", "once_cell", "regex", "serde", @@ -1527,7 +1659,7 @@ checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" dependencies = [ "crunchy", "fixed-hash 0.8.0", - "impl-codec", + "impl-codec 0.6.0", "impl-rlp", "impl-serde", "scale-info", @@ -1544,7 +1676,7 @@ dependencies = [ "ethereum-types", "hash-db", "hash256-std-hasher", - "parity-scale-codec", + "parity-scale-codec 3.6.3", "rlp", "scale-info", "serde", @@ -1560,7 +1692,7 @@ checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" dependencies = [ "ethbloom", "fixed-hash 0.8.0", - "impl-codec", + "impl-codec 0.6.0", "impl-rlp", "impl-serde", "primitive-types 0.12.1", @@ -1568,6 +1700,12 @@ dependencies = [ "uint", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "evm" version = "0.39.0" @@ -1580,7 +1718,7 @@ dependencies = [ "evm-gasometer", "evm-runtime", "log", - "parity-scale-codec", + "parity-scale-codec 3.6.3", "primitive-types 0.12.1", "rlp", "scale-info", @@ -1593,7 +1731,7 @@ name = "evm-core" version = "0.39.0" source = "git+https://github.com/aurora-is-near/sputnikvm.git?tag=v0.38.0-aurora#fcc538cc1f7f91156ef66564a8ac032a82bd4b9e" dependencies = [ - "parity-scale-codec", + "parity-scale-codec 3.6.3", "primitive-types 0.12.1", "scale-info", "serde", @@ -1623,13 +1761,35 @@ dependencies = [ ] [[package]] -name = "fallible-iterator" -version = "0.2.0" +name = "failure" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", + "failure_derive", +] [[package]] -name = "fastrand" +name = "failure_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "synstructure", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fastrand" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" @@ -1637,19 +1797,31 @@ dependencies = [ "instant", ] +[[package]] +name = "filetime" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.16", + "windows-sys 0.48.0", +] + [[package]] name = "finite-wasm" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d393fee07818ceda80e844cdcbd191b16a7be290a994210ea30c4677a39db0e8" +checksum = "f5f27c2426a53dc2e378578b37f004c8760dbe86dc193dad3c486cd9f8e9fe04" dependencies = [ - "bitvec", + "bitvec 1.0.1", "dissimilar", "num-traits", "prefix-sum-vec", "thiserror", - "wasm-encoder 0.22.1", - "wasmparser 0.99.0", + "wasm-encoder 0.26.0", + "wasmparser 0.104.0", "wasmprinter", ] @@ -1659,6 +1831,9 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" dependencies = [ + "byteorder", + "rand 0.8.5", + "rustc-hex", "static_assertions", ] @@ -1680,12 +1855,37 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "flate2" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -1764,6 +1964,21 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.28" @@ -1772,7 +1987,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -1814,15 +2029,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "generic-array" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" -dependencies = [ - "typenum", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1878,7 +2084,7 @@ version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044" dependencies = [ - "bitflags", + "bitflags 1.3.2", "libc", "libgit2-sys", "log", @@ -1966,15 +2172,6 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" -[[package]] -name = "heapsize" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" -dependencies = [ - "winapi", -] - [[package]] name = "heck" version = "0.3.3" @@ -2001,18 +2198,15 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] -name = "hermit-abi" -version = "0.3.1" +name = "hex" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" [[package]] name = "hex" @@ -2049,10 +2243,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.7", + "generic-array", "hmac 0.8.1", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "http" version = "0.2.9" @@ -2123,6 +2326,19 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.57" @@ -2179,13 +2395,22 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "impl-codec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443" +dependencies = [ + "parity-scale-codec 2.3.1", +] + [[package]] name = "impl-codec" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" dependencies = [ - "parity-scale-codec", + "parity-scale-codec 3.6.3", ] [[package]] @@ -2253,23 +2478,37 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "windows-sys 0.48.0", ] +[[package]] +name = "ipnet" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" + [[package]] name = "is-terminal" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", - "rustix 0.37.20", + "hermit-abi 0.3.2", + "rustix 0.38.4", "windows-sys 0.48.0", ] +[[package]] +name = "is_executable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577" +dependencies = [ + "winapi", +] + [[package]] name = "itertools" version = "0.10.5" @@ -2281,9 +2520,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" [[package]] name = "jobserver" @@ -2318,17 +2557,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "lazy-static-include" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b111244b70d4cf22aaaf8e0461ede19d623880f0f4779ee33dc35850a825bec3" -dependencies = [ - "lazy_static", - "manifest-dir-macros", - "syn 2.0.22", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -2392,7 +2620,6 @@ dependencies = [ "glob", "libc", "libz-sys", - "tikv-jemalloc-sys", "zstd-sys", ] @@ -2483,13 +2710,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] -name = "lock_api" -version = "0.3.4" +name = "linux-raw-sys" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" [[package]] name = "lock_api" @@ -2545,25 +2769,13 @@ dependencies = [ "libc", ] -[[package]] -name = "manifest-dir-macros" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "450e5ef583bc05177c4975b9ea907047091a9f62e74e81fcafb99dbffac51e7e" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.22", -] - [[package]] name = "matchers" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -2587,17 +2799,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" dependencies = [ - "rustix 0.37.20", -] - -[[package]] -name = "memmap" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -dependencies = [ - "libc", - "winapi", + "rustix 0.37.23", ] [[package]] @@ -2633,6 +2835,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2641,9 +2849,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] @@ -2655,7 +2863,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -2672,57 +2879,87 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "near-abi" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73" +dependencies = [ + "borsh 0.9.3", + "schemars", + "semver", + "serde", +] + [[package]] name = "near-account-id" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" dependencies = [ - "borsh 0.10.3", + "borsh 0.9.3", "serde", ] [[package]] name = "near-account-id" -version = "0.16.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12791d0f273e04609010d68deb6e1cd940659ad420edfa2e48238117154f1d5b" +checksum = "1d924011380de759c3dc6fdbcda37a19a5c061f56dab69d28a34ecee765e23e4" dependencies = [ - "arbitrary", - "borsh 0.10.3", + "borsh 0.9.3", "serde", ] [[package]] -name = "near-cache" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-account-id" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0cb40869cab7f5232f934f45db35bffe0f2d2a7cb0cd0346202fbe4ebf2dd7" dependencies = [ - "lru", + "borsh 0.10.3", + "serde", ] [[package]] name = "near-cache" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa597590d8615c2aef880a55cf70701d0c6348a90b9806297591d81f2acef35" +checksum = "1b93fc90f75d3bb22eb6587130173630547b08e769f2936d15dc7c62b925343b" dependencies = [ "lru", ] [[package]] name = "near-chain-configs" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1faf676a95bd1718b06e5957e01a9415fedf7900f32d94d5bcf70abd678b10a2" dependencies = [ "anyhow", "chrono", "derive_more", - "near-config-utils 0.0.0", - "near-crypto 0.0.0", - "near-o11y 0.0.0", - "near-primitives 0.0.0", + "near-crypto 0.15.0", + "near-primitives 0.15.0", "num-rational 0.3.2", - "once_cell", "serde", "serde_json", "sha2 0.10.7", @@ -2732,8 +2969,9 @@ dependencies = [ [[package]] name = "near-config-utils" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5523e7dce493c45bc3241eb3100d943ec471852f9b1f84b46a34789eadf17031" dependencies = [ "anyhow", "json_comments", @@ -2742,37 +2980,50 @@ dependencies = [ ] [[package]] -name = "near-config-utils" -version = "0.16.1" +name = "near-crypto" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "137b6bbd477dc0ff1149e22c5e1f3f168a1f37d9d67f1519f058a5db81df3506" +checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" dependencies = [ - "anyhow", - "json_comments", + "arrayref", + "blake2", + "borsh 0.9.3", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "near-account-id 0.14.0", + "once_cell", + "parity-secp256k1", + "primitive-types 0.10.1", + "rand 0.7.3", + "rand_core 0.5.1", + "serde", + "serde_json", + "subtle", "thiserror", - "tracing", ] [[package]] name = "near-crypto" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7754612b47737d277fb818e9fdbb1406e90f9e57151c55c3584d714421976cb6" dependencies = [ + "arrayref", "blake2", - "borsh 0.10.3", + "borsh 0.9.3", "bs58", "c2-chacha", "curve25519-dalek", "derive_more", "ed25519-dalek", - "hex", - "near-account-id 0.0.0", - "near-config-utils 0.0.0", - "near-stdx", + "near-account-id 0.15.0", "once_cell", "primitive-types 0.10.1", "rand 0.7.3", - "secp256k1 0.27.0", + "secp256k1 0.24.3", "serde", "serde_json", "subtle", @@ -2781,9 +3032,9 @@ dependencies = [ [[package]] name = "near-crypto" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "659a96750c4d933e4f00a50c66ba9948a32b862e5ecd6a952beee881b1cd2aaf" +checksum = "ff6b382b626e7e0cd372d027c6672ac97b4b6ee6114288c9e58d8180b935d315" dependencies = [ "blake2", "borsh 0.10.3", @@ -2792,14 +3043,14 @@ dependencies = [ "curve25519-dalek", "derive_more", "ed25519-dalek", - "hex", - "near-account-id 0.16.1", - "near-config-utils 0.16.1", + "hex 0.4.3", + "near-account-id 0.17.0", + "near-config-utils", "near-stdx", "once_cell", "primitive-types 0.10.1", "rand 0.7.3", - "secp256k1 0.24.3", + "secp256k1 0.27.0", "serde", "serde_json", "subtle", @@ -2808,48 +3059,59 @@ dependencies = [ [[package]] name = "near-fmt" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c44c842c6cfcd9b8c387cccd4cd0619a5f21920cde5d5c292af3cc5d40510672" dependencies = [ - "near-primitives-core 0.0.0", + "near-primitives-core 0.17.0", ] [[package]] -name = "near-o11y" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-jsonrpc-client" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1335ffce1476da6516dcd22b26cece1a495fc725c0e8fec1879073752ac068d" dependencies = [ - "actix", - "atty", - "clap 4.3.9", - "near-crypto 0.0.0", - "near-primitives-core 0.0.0", - "once_cell", - "opentelemetry", - "opentelemetry-otlp", - "opentelemetry-semantic-conventions", - "prometheus", + "borsh 0.9.3", + "lazy_static", + "log", + "near-chain-configs", + "near-crypto 0.15.0", + "near-jsonrpc-primitives", + "near-primitives 0.15.0", + "reqwest", "serde", - "strum", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "near-jsonrpc-primitives" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ada226c74f05508c516f109a97b9f23335120d0bfda208f0d187b6bbfe6eef5a" +dependencies = [ + "near-chain-configs", + "near-crypto 0.15.0", + "near-primitives 0.15.0", + "near-rpc-error-macro 0.15.0", + "serde", + "serde_json", "thiserror", - "tokio", - "tracing", - "tracing-appender", - "tracing-opentelemetry", - "tracing-subscriber", ] [[package]] name = "near-o11y" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445cbd86499dbabf68d34d95d9a45c680da5446e226f4982ce488fcf8556b23f" +checksum = "af7d35397b02b131c188c72f3885e97daeccab134ec2fc8cc0073a94cf1cfe19" dependencies = [ "actix", "atty", - "clap 3.2.25", - "near-crypto 0.16.1", - "near-primitives-core 0.16.1", + "clap", + "near-crypto 0.17.0", + "near-primitives-core 0.17.0", "once_cell", "opentelemetry", "opentelemetry-otlp", @@ -2866,58 +3128,69 @@ dependencies = [ ] [[package]] -name = "near-pool" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" -dependencies = [ - "borsh 0.10.3", - "near-crypto 0.0.0", - "near-o11y 0.0.0", - "near-primitives 0.0.0", +name = "near-primitives" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" +dependencies = [ + "borsh 0.9.3", + "byteorder", + "bytesize", + "chrono", + "derive_more", + "easy-ext", + "hex 0.4.3", + "near-crypto 0.14.0", + "near-primitives-core 0.14.0", + "near-rpc-error-macro 0.14.0", + "near-vm-errors 0.14.0", + "num-rational 0.3.2", "once_cell", - "rand 0.8.5", + "primitive-types 0.10.1", + "rand 0.7.3", + "reed-solomon-erasure", + "serde", + "serde_json", + "smart-default", + "strum", + "thiserror", ] [[package]] name = "near-primitives" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97670b302dce15f09bba50f24c67aa08130fd01528cc61d4415892401e88e974" dependencies = [ - "arbitrary", - "borsh 0.10.3", + "borsh 0.9.3", + "byteorder", "bytesize", "cfg-if 1.0.0", "chrono", "derive_more", "easy-ext", - "enum-map", - "hex", - "near-crypto 0.0.0", - "near-fmt", - "near-primitives-core 0.0.0", - "near-rpc-error-macro 0.0.0", - "near-stdx", - "near-vm-errors 0.0.0", + "hex 0.4.3", + "near-crypto 0.15.0", + "near-primitives-core 0.15.0", + "near-rpc-error-macro 0.15.0", + "near-vm-errors 0.15.0", "num-rational 0.3.2", "once_cell", "primitive-types 0.10.1", - "rand 0.8.5", + "rand 0.7.3", "reed-solomon-erasure", "serde", "serde_json", - "serde_yaml", "smart-default", "strum", "thiserror", - "time 0.3.22", - "tracing", ] [[package]] name = "near-primitives" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4c030f28e8f988698145e7753b83bb54c05838c3afdd44835cc7c32c327ea1e" +checksum = "05f7051aaf199adc4d068620fca6d5f70f906a1540d03a8bb3701271f8881835" dependencies = [ "arbitrary", "borsh 0.10.3", @@ -2927,13 +3200,13 @@ dependencies = [ "derive_more", "easy-ext", "enum-map", - "hex", - "near-crypto 0.16.1", - "near-o11y 0.16.1", - "near-primitives-core 0.16.1", - "near-rpc-error-macro 0.16.1", + "hex 0.4.3", + "near-crypto 0.17.0", + "near-fmt", + "near-primitives-core 0.17.0", + "near-rpc-error-macro 0.17.0", "near-stdx", - "near-vm-errors 0.16.1", + "near-vm-errors 0.17.0", "num-rational 0.3.2", "once_cell", "primitive-types 0.10.1", @@ -2941,51 +3214,67 @@ dependencies = [ "reed-solomon-erasure", "serde", "serde_json", + "serde_with", "serde_yaml", "smart-default", "strum", "thiserror", - "time 0.3.22", - "tokio", + "time 0.3.23", "tracing", ] [[package]] name = "near-primitives-core" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" +dependencies = [ + "base64 0.11.0", + "borsh 0.9.3", + "bs58", + "derive_more", + "near-account-id 0.14.0", + "num-rational 0.3.2", + "serde", + "sha2 0.10.7", + "strum", +] + +[[package]] +name = "near-primitives-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7929e19d862221949734c4a0063a8f55e7069de3a2ebc2d4f4c13497a5e953cb" dependencies = [ - "arbitrary", "base64 0.13.1", - "borsh 0.10.3", + "borsh 0.9.3", "bs58", "derive_more", - "enum-map", - "near-account-id 0.0.0", + "near-account-id 0.15.0", "num-rational 0.3.2", "serde", "serde_repr", "sha2 0.10.7", "strum", - "thiserror", ] [[package]] name = "near-primitives-core" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe2059d16efc42ef7f9514f30910d32b67c01fee9b70c1fd28d50545ca145d88" +checksum = "775fec19ef51a341abdbf792a9dda5b4cb89f488f681b2fd689b9321d24db47b" dependencies = [ "arbitrary", - "base64 0.13.1", + "base64 0.21.2", "borsh 0.10.3", "bs58", "derive_more", "enum-map", - "near-account-id 0.16.1", + "near-account-id 0.17.0", "num-rational 0.3.2", "serde", "serde_repr", + "serde_with", "sha2 0.10.7", "strum", "thiserror", @@ -2993,259 +3282,205 @@ dependencies = [ [[package]] name = "near-rpc-error-core" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ee0b41c75ef859c193a8ff1dadfa0c8207bc0ac447cc22259721ad769a1408" dependencies = [ "quote", "serde", - "syn 2.0.22", + "syn 1.0.109", ] [[package]] name = "near-rpc-error-core" -version = "0.16.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28f8f38dcfeba3d0d3bc60ce292ddb1f76a428a590e32de7fc3d5d431b9635ea" +checksum = "36addf90cc04bd547a627b3a292f59d7de4dd6fb5042115419ae901b93ce6c2d" dependencies = [ "quote", "serde", "syn 1.0.109", ] +[[package]] +name = "near-rpc-error-core" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c1eda300e2e78f4f945ae58117d49e806899f4a51ee2faa09eda5ebc2e6571" +dependencies = [ + "quote", + "serde", + "syn 2.0.25", +] + [[package]] name = "near-rpc-error-macro" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e837bd4bacd807073ec5ceb85708da7f721b46a4c2a978de86027fb0034ce31" dependencies = [ - "fs2", - "near-rpc-error-core 0.0.0", + "near-rpc-error-core 0.14.0", "serde", - "syn 2.0.22", + "syn 1.0.109", ] [[package]] name = "near-rpc-error-macro" -version = "0.16.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca4e8d6887b344f3e2f8281c1ad2cc93dcbcb683b546726a4ce1ab1dfa623a" +checksum = "0b5beb352f3b91d8c491646c2fa4fdbbbf463c7b9c0226951c28f0197de44f99" dependencies = [ - "fs2", - "near-rpc-error-core 0.16.1", + "near-rpc-error-core 0.15.0", "serde", "syn 1.0.109", ] +[[package]] +name = "near-rpc-error-macro" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31d2dadd765101c77e664029dd6fbec090e696877d4ae903c620d02ceda4969a" +dependencies = [ + "fs2", + "near-rpc-error-core 0.17.0", + "serde", + "syn 2.0.25", +] + +[[package]] +name = "near-sandbox-utils" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7479b0a2c52890000d410c6e4ba4f851334280530fa7446b78bcaf4683fe69b0" +dependencies = [ + "anyhow", + "async-process", + "binary-install", + "chrono", + "fs2", + "hex 0.3.2", + "home", +] + [[package]] name = "near-sdk" -version = "3.1.0" -source = "git+https://github.com/aurora-is-near/near-sdk-rs.git?rev=cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003#cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" dependencies = [ "base64 0.13.1", "borsh 0.9.3", "bs58", - "near-primitives-core 0.0.0", + "near-abi", + "near-crypto 0.14.0", + "near-primitives 0.14.0", + "near-primitives-core 0.14.0", "near-sdk-macros", - "near-vm-logic 0.0.0", + "near-sys", + "near-vm-logic 0.14.0", + "once_cell", + "schemars", "serde", "serde_json", "wee_alloc", ] -[[package]] -name = "near-sdk-core" -version = "3.1.0" -source = "git+https://github.com/aurora-is-near/near-sdk-rs.git?rev=cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003#cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" -dependencies = [ - "Inflector", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "near-sdk-macros" -version = "3.1.0" -source = "git+https://github.com/aurora-is-near/near-sdk-rs.git?rev=cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003#cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4907affc9f5ed559456509188ff0024f1f2099c0830e6bdb66eb61d5b75912c0" dependencies = [ - "near-sdk-core", + "Inflector", "proc-macro2", "quote", "syn 1.0.109", ] -[[package]] -name = "near-sdk-sim" -version = "3.2.0" -source = "git+https://github.com/aurora-is-near/near-sdk-rs.git?rev=cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003#cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" -dependencies = [ - "chrono", - "funty 1.1.0", - "lazy-static-include", - "near-chain-configs", - "near-crypto 0.0.0", - "near-pool", - "near-primitives 0.0.0", - "near-sdk", - "near-store", - "near-vm-logic 0.0.0", - "node-runtime", -] - -[[package]] -name = "near-stable-hasher" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" - [[package]] name = "near-stable-hasher" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfcd68760c75c35b958e5d243878375996f9203747c5e057b8ae513096b6edf4" +checksum = "769a3c0fcaf0686efb1e103cb5a50c62653ac5c1312a6eb910f6c7fe0158e36f" [[package]] name = "near-stdx" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc1279be274b9a49c2cb4b62541241a1ff6745cb77ca81ece7f949cfbc229bff" +checksum = "6540152fba5e96fe5d575b79e8cd244cf2add747bb01362426bdc069bc3a23bc" [[package]] -name = "near-store" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" -dependencies = [ - "actix", - "actix-rt", - "anyhow", - "borsh 0.10.3", - "bytesize", - "crossbeam", - "derive_more", - "elastic-array", - "enum-map", - "fs2", - "itertools", - "itoa", - "lru", - "near-crypto 0.0.0", - "near-fmt", - "near-o11y 0.0.0", - "near-primitives 0.0.0", - "near-stdx", - "num_cpus", - "once_cell", - "rand 0.8.5", - "rlimit", - "rocksdb", - "serde", - "serde_json", - "strum", - "tempfile", - "thiserror", - "tokio", - "tracing", -] +name = "near-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e307313276eaeced2ca95740b5639e1f3125b7c97f0a1151809d105f1aa8c6d3" [[package]] -name = "near-vm-compiler" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-units" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a2b77f295d398589eeee51ad0887905ef1734fb12b45cb6d77bd7e401988b9" dependencies = [ - "enumset", - "finite-wasm", - "near-vm-types", - "near-vm-vm", - "rkyv", - "smallvec", - "target-lexicon 0.12.8", - "thiserror", - "tracing", - "wasmparser 0.99.0", + "near-units-core", + "near-units-macro", ] [[package]] -name = "near-vm-compiler-singlepass" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-units-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89aa2a7985de87a08ca35f28abd8d00f0f901e704257e6e029aadef981386bc6" dependencies = [ - "dynasm", - "dynasmrt", - "enumset", - "finite-wasm", - "lazy_static", - "memoffset 0.6.5", - "more-asserts", - "near-vm-compiler", - "near-vm-types", - "near-vm-vm", - "rayon", - "smallvec", - "strum", - "tracing", + "num-format", + "regex", ] [[package]] -name = "near-vm-engine" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-units-macro" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ab45d066220846f9bd5c21e9ab88c47c892edd36f962ada78bf8308523171a" dependencies = [ - "backtrace", - "enumset", - "finite-wasm", - "lazy_static", - "memmap2", - "more-asserts", - "near-vm-compiler", - "near-vm-types", - "near-vm-vm", - "rustc-demangle", - "target-lexicon 0.12.8", - "thiserror", + "near-units-core", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] -name = "near-vm-engine-universal" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-vm-errors" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" dependencies = [ - "cfg-if 1.0.0", - "enumset", - "finite-wasm", - "leb128", - "near-vm-compiler", - "near-vm-engine", - "near-vm-types", - "near-vm-vm", - "prefix-sum-vec", - "region", - "rkyv", - "thiserror", - "tracing", - "wasmparser 0.99.0", - "winapi", + "borsh 0.9.3", + "near-account-id 0.14.0", + "near-rpc-error-macro 0.14.0", + "serde", ] [[package]] name = "near-vm-errors" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5591c9c8afa83a040cb5c3f29bc52b2efae2c32d4bcaee1bba723738da1a5cf6" dependencies = [ - "borsh 0.10.3", - "near-account-id 0.0.0", - "near-rpc-error-macro 0.0.0", + "borsh 0.9.3", + "near-account-id 0.15.0", + "near-rpc-error-macro 0.15.0", "serde", "strum", - "thiserror", ] [[package]] name = "near-vm-errors" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2d3eab1e050fdc3e036c803784cf45582661ae2dd07bac3bd373ba9c049715" +checksum = "ec545d1bede0579e7c15dd2dce9b998dc975c52f2165702ff40bec7ff69728bb" dependencies = [ "borsh 0.10.3", - "near-account-id 0.16.1", - "near-rpc-error-macro 0.16.1", + "near-account-id 0.17.0", + "near-rpc-error-macro 0.17.0", "serde", "strum", "thiserror", @@ -3253,41 +3488,19 @@ dependencies = [ [[package]] name = "near-vm-logic" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" -dependencies = [ - "borsh 0.10.3", - "ed25519-dalek", - "near-account-id 0.0.0", - "near-crypto 0.0.0", - "near-fmt", - "near-o11y 0.0.0", - "near-primitives 0.0.0", - "near-primitives-core 0.0.0", - "near-stdx", - "near-vm-errors 0.0.0", - "ripemd", - "serde", - "sha2 0.10.7", - "sha3", - "zeropool-bn", -] - -[[package]] -name = "near-vm-logic" -version = "0.16.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85068a639fca198f88d1693f5f37011acdb6dd0368670c4812db5e338b498d8e" +checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2" dependencies = [ - "borsh 0.10.3", - "ed25519-dalek", - "near-account-id 0.16.1", - "near-crypto 0.16.1", - "near-o11y 0.16.1", - "near-primitives 0.16.1", - "near-primitives-core 0.16.1", - "near-stdx", - "near-vm-errors 0.16.1", + "base64 0.13.1", + "borsh 0.9.3", + "bs58", + "byteorder", + "near-account-id 0.14.0", + "near-crypto 0.14.0", + "near-primitives 0.14.0", + "near-primitives-core 0.14.0", + "near-vm-errors 0.14.0", "ripemd", "serde", "sha2 0.10.7", @@ -3296,148 +3509,59 @@ dependencies = [ ] [[package]] -name = "near-vm-runner" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" -dependencies = [ - "anyhow", - "borsh 0.10.3", - "finite-wasm", - "loupe", - "memoffset 0.6.5", - "near-cache 0.0.0", - "near-primitives 0.0.0", - "near-stable-hasher 0.0.0", - "near-vm-compiler", - "near-vm-compiler-singlepass", - "near-vm-engine", - "near-vm-engine-universal", - "near-vm-errors 0.0.0", - "near-vm-logic 0.0.0", - "near-vm-types", - "near-vm-vm", - "once_cell", - "parity-wasm 0.41.0", - "parity-wasm 0.42.2", - "prefix-sum-vec", - "pwasm-utils", - "serde", - "tracing", - "wasmer-compiler-near", - "wasmer-compiler-singlepass-near", - "wasmer-engine-near", - "wasmer-engine-universal-near", - "wasmer-runtime-core-near", - "wasmer-runtime-near", - "wasmer-types-near", - "wasmer-vm-near", - "wasmparser 0.78.2", - "wasmtime", -] - -[[package]] -name = "near-vm-runner" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e927881ee82340d67a6aefb2ecd778f43a3984728cc2af94516737cd0a96e5d9" -dependencies = [ - "anyhow", - "borsh 0.10.3", - "loupe", - "memoffset 0.6.5", - "near-cache 0.16.1", - "near-primitives 0.16.1", - "near-stable-hasher 0.16.1", - "near-vm-errors 0.16.1", - "near-vm-logic 0.16.1", - "once_cell", - "parity-wasm 0.41.0", - "parity-wasm 0.42.2", - "pwasm-utils", - "serde", - "tracing", - "wasmer-compiler-near", - "wasmer-compiler-singlepass-near", - "wasmer-engine-near", - "wasmer-engine-universal-near", - "wasmer-types-near", - "wasmer-vm-near", - "wasmparser 0.78.2", - "wasmtime", -] - -[[package]] -name = "near-vm-types" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" -dependencies = [ - "indexmap 1.9.3", - "num-traits", - "rkyv", - "thiserror", -] - -[[package]] -name = "near-vm-vm" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" -dependencies = [ - "backtrace", - "cc", - "cfg-if 1.0.0", - "finite-wasm", - "indexmap 1.9.3", - "libc", - "memoffset 0.6.5", - "more-asserts", - "near-vm-types", - "region", - "rkyv", - "thiserror", - "tracing", - "wasmparser 0.99.0", - "winapi", -] - -[[package]] -name = "nix" -version = "0.15.0" +name = "near-vm-logic" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" +checksum = "30d7487c678ed1963a0ecd5033f72bb41caa58debd6fe8025a9bef6e1a6a519a" dependencies = [ - "bitflags", - "cc", - "cfg-if 0.1.10", - "libc", - "void", + "borsh 0.10.3", + "ed25519-dalek", + "near-account-id 0.17.0", + "near-crypto 0.17.0", + "near-fmt", + "near-o11y", + "near-primitives 0.17.0", + "near-primitives-core 0.17.0", + "near-stdx", + "near-vm-errors 0.17.0", + "ripemd", + "serde", + "sha2 0.10.7", + "sha3", + "zeropool-bn", ] [[package]] -name = "node-runtime" -version = "0.0.0" -source = "git+https://github.com/birchmd/nearcore.git?rev=71c9b3f4c62f1bff24982a179be64e6d03df0e16#71c9b3f4c62f1bff24982a179be64e6d03df0e16" +name = "near-vm-runner" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a920e3ca5afa0f0a9016c7cde95030eb60c63f2f3834f691614f12aebb11909" dependencies = [ + "anyhow", "borsh 0.10.3", - "hex", - "near-chain-configs", - "near-crypto 0.0.0", - "near-o11y 0.0.0", - "near-primitives 0.0.0", - "near-store", - "near-vm-errors 0.0.0", - "near-vm-logic 0.0.0", - "near-vm-runner 0.0.0", - "num-bigint 0.3.3", - "num-rational 0.3.2", - "num-traits", + "finite-wasm", + "loupe", + "memoffset 0.6.5", + "near-cache", + "near-primitives 0.17.0", + "near-stable-hasher", + "near-vm-errors 0.17.0", + "near-vm-logic 0.17.0", "once_cell", - "rand 0.8.5", - "rayon", + "parity-wasm 0.41.0", + "parity-wasm 0.42.2", + "prefix-sum-vec", + "pwasm-utils", "serde", - "serde_json", - "sha2 0.10.7", - "thiserror", "tracing", + "wasmer-compiler-near", + "wasmer-compiler-singlepass-near", + "wasmer-engine-near", + "wasmer-engine-universal-near", + "wasmer-types-near", + "wasmer-vm-near", + "wasmparser 0.78.2", + "wasmtime", ] [[package]] @@ -3505,6 +3629,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec 0.7.4", + "itoa", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -3562,11 +3696,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.2", "libc", ] @@ -3584,9 +3718,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.4" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" dependencies = [ "memchr", ] @@ -3609,6 +3743,32 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl" +version = "0.10.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" +dependencies = [ + "bitflags 1.3.2", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.25", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -3675,12 +3835,6 @@ dependencies = [ "opentelemetry", ] -[[package]] -name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - [[package]] name = "overload" version = "0.1.1" @@ -3688,34 +3842,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] -name = "page_size" -version = "0.4.2" +name = "parity-scale-codec" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" +checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909" dependencies = [ - "libc", - "winapi", + "arrayvec 0.7.4", + "bitvec 0.20.4", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive 2.3.1", + "serde", ] [[package]] name = "parity-scale-codec" -version = "3.6.1" +version = "3.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2287753623c76f953acd29d15d8100bcab84d29db78fb6f352adb3c53e83b967" +checksum = "756d439303e94fae44f288ba881ad29670c65b0c4b0e05674ca81061bb65f2c5" dependencies = [ "arrayvec 0.7.4", - "bitvec", + "bitvec 1.0.1", "byte-slice-cast", "impl-trait-for-tuples", - "parity-scale-codec-derive", + "parity-scale-codec-derive 3.6.3", "serde", ] [[package]] name = "parity-scale-codec-derive" -version = "3.6.1" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b6937b5e67bfba3351b87b040d48352a2fcb6ad72f81855412ce97b45c8f110" +checksum = "9d884d78fcf214d70b1e239fcd1c6e5e95aa3be1881918da2e488cc946c7a476" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -3723,6 +3893,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "parity-secp256k1" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1" +dependencies = [ + "arrayvec 0.5.2", + "cc", + "cfg-if 0.1.10", + "rand 0.7.3", +] + [[package]] name = "parity-wasm" version = "0.41.0" @@ -3736,14 +3918,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" [[package]] -name = "parking_lot" -version = "0.10.2" +name = "parking" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" -dependencies = [ - "lock_api 0.3.4", - "parking_lot_core 0.7.3", -] +checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" [[package]] name = "parking_lot" @@ -3751,22 +3929,8 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "lock_api 0.4.10", - "parking_lot_core 0.9.8", -] - -[[package]] -name = "parking_lot_core" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93f386bb233083c799e6e642a9d73db98c24a5deeb95ffc85bf281255dffc98" -dependencies = [ - "cfg-if 0.1.10", - "cloudabi", - "libc", - "redox_syscall 0.1.57", - "smallvec", - "winapi", + "lock_api", + "parking_lot_core", ] [[package]] @@ -3784,9 +3948,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "b4b27ab7be369122c218afc2079489cdcb4b517c0a3fc386ff11e1fedfcc2b35" [[package]] name = "peeking_take_while" @@ -3825,34 +3989,34 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ - "siphasher", + "siphasher 0.3.10", ] [[package]] name = "pin-project" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" +checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" +checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" [[package]] name = "pin-utils" @@ -3894,6 +4058,31 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if 1.0.0", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "portpicker" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9" +dependencies = [ + "rand 0.8.5", +] + [[package]] name = "postgres" version = "0.19.4" @@ -3956,6 +4145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" dependencies = [ "fixed-hash 0.7.0", + "impl-codec 0.5.1", "uint", ] @@ -3966,7 +4156,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" dependencies = [ "fixed-hash 0.8.0", - "impl-codec", + "impl-codec 0.6.0", "impl-rlp", "impl-serde", "scale-info", @@ -4018,9 +4208,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -4035,7 +4225,7 @@ dependencies = [ "fnv", "lazy_static", "memchr", - "parking_lot 0.12.1", + "parking_lot", "protobuf", "thiserror", ] @@ -4148,6 +4338,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" + [[package]] name = "radium" version = "0.7.0" @@ -4253,13 +4449,44 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom 0.1.16", + "redox_syscall 0.1.57", + "rust-argon2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.10", + "redox_syscall 0.2.16", + "thiserror", ] [[package]] @@ -4285,13 +4512,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.2", + "regex-automata 0.3.2", + "regex-syntax 0.7.4", ] [[package]] @@ -4303,6 +4531,17 @@ dependencies = [ "regex-syntax 0.6.29", ] +[[package]] +name = "regex-automata" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.4", +] + [[package]] name = "regex-syntax" version = "0.6.29" @@ -4311,9 +4550,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "region" @@ -4321,7 +4560,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76e189c2369884dce920945e2ddf79b3dff49e071a167dd1817fa9c4c00d512e" dependencies = [ - "bitflags", + "bitflags 1.3.2", "libc", "mach", "winapi", @@ -4336,6 +4575,43 @@ dependencies = [ "bytecheck", ] +[[package]] +name = "reqwest" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +dependencies = [ + "base64 0.21.2", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ripemd" version = "0.1.3" @@ -4351,7 +4627,7 @@ version = "0.7.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" dependencies = [ - "bitvec", + "bitvec 1.0.1", "bytecheck", "hashbrown 0.12.3", "ptr_meta", @@ -4373,15 +4649,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "rlimit" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "347703a5ae47adf1e693144157be231dde38c72bd485925cae7407ad3e52480b" -dependencies = [ - "libc", -] - [[package]] name = "rlp" version = "0.5.2" @@ -4414,6 +4681,18 @@ dependencies = [ "librocksdb-sys", ] +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64 0.13.1", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -4432,32 +4711,23 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.17", + "semver", ] [[package]] name = "rustix" -version = "0.36.14" +version = "0.36.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14e4d67015953998ad0eb82887a0eb0129e18a7e2f3b7b0f6c422fddcd503d62" +checksum = "c37f1bd5ef1b5422177b7646cba67430579cfe2ace80f284fee876bca52ad941" dependencies = [ - "bitflags", - "errno 0.3.1", + "bitflags 1.3.2", + "errno", "io-lifetimes", "libc", "linux-raw-sys 0.1.4", @@ -4466,61 +4736,107 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.20" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ - "bitflags", - "errno 0.3.1", + "bitflags 1.3.2", + "errno", "io-lifetimes", "libc", "linux-raw-sys 0.3.8", "windows-sys 0.48.0", ] +[[package]] +name = "rustix" +version = "0.38.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +dependencies = [ + "bitflags 2.3.3", + "errno", + "libc", + "linux-raw-sys 0.4.3", + "windows-sys 0.48.0", +] + [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "dc31bd9b61a32c31f9650d18add92aa83a49ba979c143eefd27fe7177b05bd5f" [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scale-info" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +dependencies = [ + "bitvec 1.0.1", + "cfg-if 1.0.0", + "derive_more", + "parity-scale-codec 3.6.3", + "scale-info-derive", +] + +[[package]] +name = "scale-info-derive" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] -name = "same-file" -version = "1.0.6" +name = "schannel" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "winapi-util", + "windows-sys 0.48.0", ] [[package]] -name = "scale-info" -version = "2.8.0" +name = "schemars" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad560913365790f17cbf12479491169f01b9d46d29cfc7422bf8c64bdc61b731" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" dependencies = [ - "bitvec", - "cfg-if 1.0.0", - "derive_more", - "parity-scale-codec", - "scale-info-derive", + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", ] [[package]] -name = "scale-info-derive" -version = "2.8.0" +name = "schemars_derive" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19df9bd9ace6cc2fe19387c96ce677e823e07d017ceed253e7bb3d1d1bd9c73b" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" dependencies = [ - "proc-macro-crate 1.3.1", "proc-macro2", "quote", + "serde_derive_internals", "syn 1.0.109", ] @@ -4575,12 +4891,26 @@ dependencies = [ ] [[package]] -name = "semver" -version = "0.9.0" +name = "security-framework" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" dependencies = [ - "semver-parser", + "core-foundation-sys", + "libc", ] [[package]] @@ -4590,70 +4920,96 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] -name = "semver-parser" -version = "0.7.0" +name = "serde" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +dependencies = [ + "serde_derive", +] [[package]] -name = "serde" -version = "1.0.164" +name = "serde_derive" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ - "serde_derive", + "proc-macro2", + "quote", + "syn 2.0.25", ] [[package]] -name = "serde-bench" -version = "0.0.7" +name = "serde_derive_internals" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ - "byteorder", - "serde", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] -name = "serde_bytes" -version = "0.11.9" +name = "serde_json" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" dependencies = [ + "itoa", + "ryu", "serde", ] [[package]] -name = "serde_derive" -version = "1.0.164" +name = "serde_repr" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "1d89a8107374290037607734c0b73a85db7ed80cae314b3c5791f192a496e731" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] -name = "serde_json" -version = "1.0.99" +name = "serde_urlencoded" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ + "form_urlencoded", "itoa", "ryu", "serde", ] [[package]] -name = "serde_repr" -version = "0.1.12" +name = "serde_with" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02d8aa6e3c385bf084924f660ce2a3a6bd333ba55b35e8590b321f35d88513" +dependencies = [ + "base64 0.21.2", + "chrono", + "hex 0.4.3", + "indexmap 1.9.3", + "serde", + "serde_json", + "serde_with_macros", + "time 0.3.23", +] + +[[package]] +name = "serde_with_macros" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" +checksum = "edc7d5d3932fb12ce722ee5e64dd38c504efba37567f0c402f6ca728c3b8b070" dependencies = [ + "darling", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -4718,6 +5074,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +[[package]] +name = "signal-hook" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +dependencies = [ + "libc", + "signal-hook-registry", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -4739,6 +5105,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +[[package]] +name = "siphasher" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" + [[package]] name = "siphasher" version = "0.3.10" @@ -4762,9 +5134,9 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "smart-default" @@ -4862,15 +5234,27 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.22" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + [[package]] name = "tap" version = "1.0.1" @@ -4878,16 +5262,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] -name = "target-lexicon" -version = "0.10.0" +name = "tar" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", + "xattr", +] [[package]] name = "target-lexicon" -version = "0.12.8" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1c7f239eb94671427157bd93b3694320f3668d4e1eff08c7285366fd777fac" +checksum = "df8e77cb757a61f51b947ec4a7e3646efd825b73561db1c232a8ccb639e611a0" [[package]] name = "tempfile" @@ -4899,19 +5288,10 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.20", + "rustix 0.37.23", "windows-sys 0.48.0", ] -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - [[package]] name = "test-case" version = "3.1.0" @@ -4947,30 +5327,24 @@ dependencies = [ "test-case-core", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -4983,16 +5357,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tikv-jemalloc-sys" -version = "0.5.3+5.3.0-patched" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a678df20055b43e57ef8cddde41cdfda9a3c1a060b67f4c5836dfb1d78543ba8" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "time" version = "0.1.45" @@ -5006,9 +5370,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" dependencies = [ "itoa", "serde", @@ -5024,9 +5388,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" dependencies = [ "time-core", ] @@ -5067,22 +5431,21 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.19.2" +version = "1.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" +checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" dependencies = [ + "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", - "once_cell", - "parking_lot 0.12.1", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -5097,13 +5460,23 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", ] [[package]] @@ -5119,7 +5492,7 @@ dependencies = [ "futures-channel", "futures-util", "log", - "parking_lot 0.12.1", + "parking_lot", "percent-encoding", "phf", "pin-project-lite", @@ -5130,6 +5503,17 @@ dependencies = [ "tokio-util 0.7.3", ] +[[package]] +name = "tokio-retry" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" +dependencies = [ + "pin-project", + "rand 0.8.5", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" @@ -5186,9 +5570,9 @@ checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.19.11" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" +checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78" dependencies = [ "indexmap 2.0.0", "toml_datetime", @@ -5290,7 +5674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e" dependencies = [ "crossbeam-channel", - "time 0.3.22", + "time 0.3.23", "tracing-subscriber", ] @@ -5302,7 +5686,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -5398,7 +5782,7 @@ checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ "byteorder", "crunchy", - "hex", + "hex 0.4.3", "static_assertions", ] @@ -5410,9 +5794,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" [[package]] name = "unicode-normalization" @@ -5429,6 +5813,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "unsafe-libyaml" version = "0.2.8" @@ -5444,6 +5834,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -5457,6 +5848,9 @@ name = "uuid" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" +dependencies = [ + "getrandom 0.2.10", +] [[package]] name = "valuable" @@ -5477,10 +5871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "void" -version = "1.0.2" +name = "waker-fn" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "walkdir" @@ -5568,10 +5962,22 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -5590,7 +5996,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5603,9 +6009,9 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-encoder" -version = "0.22.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a584273ccc2d9311f1dd19dc3fb26054661fa3e373d53ede5d1144ba07a9acd" +checksum = "d05d0b6fcd0aeb98adf16e7975331b3c17222aa815148f5b976370ce589d80ef" dependencies = [ "leb128", ] @@ -5628,7 +6034,7 @@ dependencies = [ "enumset", "rkyv", "smallvec", - "target-lexicon 0.12.8", + "target-lexicon", "thiserror", "wasmer-types-near", "wasmer-vm-near", @@ -5666,7 +6072,7 @@ dependencies = [ "memmap2", "more-asserts", "rustc-demangle", - "target-lexicon 0.12.8", + "target-lexicon", "thiserror", "wasmer-compiler-near", "wasmer-types-near", @@ -5692,70 +6098,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wasmer-runtime-core-near" -version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3fac37da3c625e98708c5dd92d3f642aaf700fd077168d3d0fff277ec6a165" -dependencies = [ - "bincode", - "blake3", - "borsh 0.9.3", - "cc", - "digest 0.8.1", - "errno 0.2.8", - "hex", - "indexmap 1.9.3", - "lazy_static", - "libc", - "nix", - "page_size", - "parking_lot 0.10.2", - "rustc_version 0.2.3", - "serde", - "serde-bench", - "serde_bytes", - "serde_derive", - "smallvec", - "target-lexicon 0.10.0", - "wasmparser 0.51.4", - "winapi", -] - -[[package]] -name = "wasmer-runtime-near" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158e6fff11e5e1ef805af50637374d5bd43d92017beafa18992cdf7f3f7ae3e4" -dependencies = [ - "lazy_static", - "memmap", - "serde", - "serde_derive", - "wasmer-runtime-core-near", - "wasmer-singlepass-backend-near", -] - -[[package]] -name = "wasmer-singlepass-backend-near" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6edd0ba6c0bcf9b279186d4dbe81649dda3e5ef38f586865943de4dcd653f8" -dependencies = [ - "bincode", - "borsh 0.9.3", - "byteorder", - "dynasm", - "dynasmrt", - "lazy_static", - "libc", - "nix", - "serde", - "serde_derive", - "smallvec", - "wasmer-runtime-core-near", -] - [[package]] name = "wasmer-types-near" version = "2.4.0" @@ -5787,12 +6129,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wasmparser" -version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" - [[package]] name = "wasmparser" version = "0.78.2" @@ -5817,32 +6153,22 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.99.0" +version = "0.104.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef3b717afc67f848f412d4f02c127dd3e35a0eecd58c684580414df4fde01d3" +checksum = "6a396af81a7c56ad976131d6a35e4b693b78a1ea0357843bd436b4577e254a7d" dependencies = [ "indexmap 1.9.3", "url", ] -[[package]] -name = "wasmparser" -version = "0.107.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e3ac9b780c7dda0cac7a52a5d6d2d6707cc6e3451c9db209b6c758f40d7acb" -dependencies = [ - "indexmap 1.9.3", - "semver 1.0.17", -] - [[package]] name = "wasmprinter" -version = "0.2.59" +version = "0.2.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc960b30b84abca377768f3c62cff3a1c74db8c0f6759ed581827da0bd3a3fed" +checksum = "731da2505d5437cd5d6feb09457835f76186be13be7677fe00781ae99d5bbe8a" dependencies = [ "anyhow", - "wasmparser 0.107.0", + "wasmparser 0.104.0", ] [[package]] @@ -5862,7 +6188,7 @@ dependencies = [ "paste", "psm", "serde", - "target-lexicon 0.12.8", + "target-lexicon", "wasmparser 0.95.0", "wasmtime-cranelift", "wasmtime-environ", @@ -5895,7 +6221,7 @@ dependencies = [ "gimli 0.26.2", "log", "object 0.29.0", - "target-lexicon 0.12.8", + "target-lexicon", "thiserror", "wasmparser 0.95.0", "wasmtime-environ", @@ -5914,7 +6240,7 @@ dependencies = [ "log", "object 0.29.0", "serde", - "target-lexicon 0.12.8", + "target-lexicon", "thiserror", "wasmparser 0.95.0", "wasmtime-types", @@ -5936,7 +6262,7 @@ dependencies = [ "object 0.29.0", "rustc-demangle", "serde", - "target-lexicon 0.12.8", + "target-lexicon", "wasmtime-environ", "wasmtime-jit-icache-coherence", "wasmtime-runtime", @@ -5980,7 +6306,7 @@ dependencies = [ "memoffset 0.6.5", "paste", "rand 0.8.5", - "rustix 0.36.14", + "rustix 0.36.15", "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-jit-debug", @@ -6221,13 +6547,61 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529" dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "workspaces" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b13d249618f197811e3673decc81459730cf5cc09ee7246dc4bede1e9333bc" +dependencies = [ + "async-process", + "async-trait", + "base64 0.13.1", + "borsh 0.9.3", + "bs58", + "chrono", + "dirs 3.0.2", + "hex 0.4.3", + "libc", + "near-account-id 0.15.0", + "near-crypto 0.15.0", + "near-jsonrpc-client", + "near-jsonrpc-primitives", + "near-primitives 0.15.0", + "near-sandbox-utils", + "portpicker", + "rand 0.8.5", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-retry", + "tracing", + "url", +] + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" + [[package]] name = "wyz" version = "0.5.1" @@ -6237,6 +6611,15 @@ dependencies = [ "tap", ] +[[package]] +name = "xattr" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +dependencies = [ + "libc", +] + [[package]] name = "zeroize" version = "1.3.0" @@ -6254,7 +6637,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.25", ] [[package]] @@ -6271,6 +6654,20 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "zip" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +dependencies = [ + "byteorder", + "bzip2", + "crc32fast", + "flate2", + "thiserror", + "time 0.1.45", +] + [[package]] name = "zstd-sys" version = "2.0.8+zstd.1.5.5" diff --git a/Cargo.toml b/Cargo.toml index c36d5b3a8..ba7c261cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,11 @@ aurora-engine-transactions = { path = "engine-transactions", default-features = aurora-engine-types = { path = "engine-types", default-features = false } aurora-engine-modexp = { path = "engine-modexp", default-features = false } aurora-engine-test-doubles = { path = "engine-test-doubles" } +aurora-engine-workspace = { path = "engine-workspace" } engine-standalone-storage = { path = "engine-standalone-storage" } engine-standalone-tracing = { path = "engine-standalone-tracing", default-features = false, features = ["impl-serde"] } +anyhow = "1" base64 = { version = "0.21", default-features = false, features = ["alloc"] } bitflags = { version = "1", default-features = false } bn = { version = "0.5", package = "zeropool-bn", default-features = false } @@ -35,14 +37,16 @@ evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = " git2 = "0.17" hex = { version = "0.4", default-features = false, features = ["alloc"] } ibig = { version = "0.3", default-features = false, features = ["num-traits"] } +lazy_static = "1" libsecp256k1 = { version = "0.7", default-features = false } -near-crypto = "0.16" -near-primitives = "0.16" -near-primitives-core = "0.16" -near-sdk-sim = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" } -near-vm-errors = "0.16" -near-vm-logic = "0.16" -near-vm-runner = { version = "0.16", default-features = false, features = [ "wasmer2_vm", "wasmtime_vm" ] } +near-crypto = "0.17" +near-primitives = "0.17" +near-primitives-core = "0.17" +near-sdk = "4" +near-vm-errors = "0.17" +near-vm-logic = "0.17" +near-vm-runner = { version = "0.17", default-features = false, features = [ "wasmer2_vm", "wasmtime_vm" ] } +near-units = "0.2" num = { version = "0.4", default-features = false, features = ["alloc"] } postgres = "0.19" primitive-types = { version = "0.12", default-features = false, features = ["rlp", "serde_no_std"] } @@ -55,10 +59,11 @@ serde_json = { version = "1", default-features = false, features = ["alloc"] } sha2 = { version = "0.10", default-features = false } sha3 = { version = "0.10", default-features = false } tempfile = "3" +tokio = { version = "1", default-features = false, features = ["macros"] } test-case = "3.1" walrus = "0.20" wee_alloc = { version = "0.4", default-features = false } - +workspaces = "0.7" [workspace] resolver = "2" @@ -73,6 +78,7 @@ members = [ "engine-tests", "engine-transactions", "engine-types", + "engine-workspace", ] exclude = [ diff --git a/engine-precompiles/src/xcc.rs b/engine-precompiles/src/xcc.rs index 53d61a98c..874942438 100644 --- a/engine-precompiles/src/xcc.rs +++ b/engine-precompiles/src/xcc.rs @@ -240,7 +240,7 @@ pub mod state { use aurora_engine_sdk::error::ReadU32Error; use aurora_engine_sdk::io::{StorageIntermediate, IO}; - use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize}; + use aurora_engine_types::parameters::xcc::CodeVersion; use aurora_engine_types::storage::{self, KeyPrefix}; use aurora_engine_types::types::{Address, Yocto}; @@ -251,28 +251,6 @@ pub mod state { /// Amount of NEAR needed to cover storage for a router contract. pub const STORAGE_AMOUNT: Yocto = Yocto::new(2_000_000_000_000_000_000_000_000); - /// Type wrapper for version of router contracts. - #[derive( - Debug, - Clone, - Copy, - Default, - PartialEq, - Eq, - PartialOrd, - Ord, - BorshDeserialize, - BorshSerialize, - )] - pub struct CodeVersion(pub u32); - - impl CodeVersion { - #[must_use] - pub const fn increment(self) -> Self { - Self(self.0 + 1) - } - } - /// Get the address of the `wNEAR` ERC-20 contract /// /// # Panics diff --git a/engine-tests/Cargo.toml b/engine-tests/Cargo.toml index ac6e2e848..bc6c53197 100644 --- a/engine-tests/Cargo.toml +++ b/engine-tests/Cargo.toml @@ -18,6 +18,9 @@ aurora-engine-sdk = { workspace = true, features = ["std"] } aurora-engine-test-doubles.workspace = true aurora-engine-transactions = { workspace = true, features = ["std", "impl-serde"] } aurora-engine-types = { workspace = true, features = ["std", "impl-serde"] } +aurora-engine-workspace.workspace = true + +anyhow.workspace = true borsh.workspace = true bstr.workspace = true byte-slice-cast.workspace = true @@ -34,7 +37,6 @@ libsecp256k1.workspace = true near-crypto.workspace = true near-primitives-core.workspace = true near-primitives.workspace = true -near-sdk-sim.workspace = true near-vm-errors.workspace = true near-vm-logic.workspace = true near-vm-runner.workspace = true @@ -44,6 +46,7 @@ serde.workspace = true serde_json.workspace = true sha3.workspace = true tempfile.workspace = true +tokio.workspace = true walrus.workspace = true [features] diff --git a/engine-tests/src/benches/eth_deploy_code.rs b/engine-tests/src/benches/eth_deploy_code.rs index 625bfb149..30120042b 100644 --- a/engine-tests/src/benches/eth_deploy_code.rs +++ b/engine-tests/src/benches/eth_deploy_code.rs @@ -2,15 +2,16 @@ use criterion::{BatchSize, BenchmarkId, Criterion, Throughput}; use libsecp256k1::SecretKey; use crate::prelude::Wei; -use crate::test_utils::{ - address_from_secret_key, create_deploy_transaction, deploy_evm, sign_transaction, SUBMIT, +use crate::utils::{ + address_from_secret_key, create_deploy_transaction, deploy_runner, parse_eth_gas, + sign_transaction, SUBMIT, }; const INITIAL_BALANCE: Wei = Wei::new_u64(1000); const INITIAL_NONCE: u64 = 0; pub fn eth_deploy_code_benchmark(c: &mut Criterion) { - let mut runner = deploy_evm(); + let mut runner = deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); runner.create_address( @@ -40,7 +41,7 @@ pub fn eth_deploy_code_benchmark(c: &mut Criterion) { .call(SUBMIT, calling_account_id, input.clone()) .unwrap(); let gas = output.burnt_gas; - let eth_gas = crate::test_utils::parse_eth_gas(&output); + let eth_gas = parse_eth_gas(&output); // TODO(#45): capture this in a file println!("ETH_DEPLOY_CODE_{input_size:?} NEAR GAS: {gas:?}"); println!("ETH_DEPLOY_CODE_{input_size:?} ETH GAS: {eth_gas:?}"); diff --git a/engine-tests/src/benches/eth_erc20.rs b/engine-tests/src/benches/eth_erc20.rs index 8853e6e66..3c7d58411 100644 --- a/engine-tests/src/benches/eth_erc20.rs +++ b/engine-tests/src/benches/eth_erc20.rs @@ -2,15 +2,17 @@ use crate::prelude::U256; use criterion::{BatchSize, BenchmarkId, Criterion}; use libsecp256k1::SecretKey; -use crate::test_utils::erc20::{ERC20Constructor, ERC20}; -use crate::test_utils::{address_from_secret_key, deploy_evm, sign_transaction, SUBMIT}; +use crate::utils::solidity::erc20::{ERC20Constructor, ERC20}; +use crate::utils::{ + address_from_secret_key, deploy_runner, parse_eth_gas, sign_transaction, SUBMIT, +}; const INITIAL_BALANCE: u64 = 1000; const INITIAL_NONCE: u64 = 0; const TRANSFER_AMOUNT: u64 = 67; pub fn eth_erc20_benchmark(c: &mut Criterion) { - let mut runner = deploy_evm(); + let mut runner = deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); runner.create_address( @@ -66,7 +68,7 @@ pub fn eth_erc20_benchmark(c: &mut Criterion) { .call(SUBMIT, calling_account_id, mint_tx_bytes.clone()) .unwrap(); let gas = output.burnt_gas; - let eth_gas = crate::test_utils::parse_eth_gas(&output); + let eth_gas = parse_eth_gas(&output); // TODO(#45): capture this in a file println!("ETH_ERC20_MINT NEAR GAS: {gas:?}"); println!("ETH_ERC20_MINT ETH GAS: {eth_gas:?}"); @@ -77,7 +79,7 @@ pub fn eth_erc20_benchmark(c: &mut Criterion) { .call(SUBMIT, calling_account_id, transfer_tx_bytes.clone()) .unwrap(); let gas = output.burnt_gas; - let eth_gas = crate::test_utils::parse_eth_gas(&output); + let eth_gas = parse_eth_gas(&output); // TODO(#45): capture this in a file println!("ETH_ERC20_TRANSFER NEAR GAS: {gas:?}"); println!("ETH_ERC20_TRANSFER ETH GAS: {eth_gas:?}"); diff --git a/engine-tests/src/benches/eth_standard_precompiles.rs b/engine-tests/src/benches/eth_standard_precompiles.rs index 76ebd301a..c48cc6cab 100644 --- a/engine-tests/src/benches/eth_standard_precompiles.rs +++ b/engine-tests/src/benches/eth_standard_precompiles.rs @@ -3,14 +3,16 @@ use criterion::{BatchSize, BenchmarkId, Criterion}; use libsecp256k1::SecretKey; use crate::prelude::Wei; -use crate::test_utils::standard_precompiles::{PrecompilesConstructor, PrecompilesContract}; -use crate::test_utils::{address_from_secret_key, deploy_evm, sign_transaction, SUBMIT}; +use crate::utils::solidity::standard_precompiles::{PrecompilesConstructor, PrecompilesContract}; +use crate::utils::{ + address_from_secret_key, deploy_runner, parse_eth_gas, sign_transaction, SUBMIT, +}; const INITIAL_BALANCE: Wei = Wei::new_u64(1000); const INITIAL_NONCE: u64 = 0; pub fn eth_standard_precompiles_benchmark(c: &mut Criterion) { - let mut runner = deploy_evm(); + let mut runner = deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); runner.create_address( @@ -48,7 +50,7 @@ pub fn eth_standard_precompiles_benchmark(c: &mut Criterion) { .call(SUBMIT, calling_account_id, tx_bytes.clone()) .unwrap(); let gas = output.burnt_gas; - let eth_gas = crate::test_utils::parse_eth_gas(&output); + let eth_gas = parse_eth_gas(&output); // TODO(#45): capture this in a file println!("ETH_STANDARD_PRECOMPILES_{name} NEAR GAS: {gas:?}"); println!("ETH_STANDARD_PRECOMPILES_{name} ETH GAS: {eth_gas:?}"); diff --git a/engine-tests/src/benches/eth_transfer.rs b/engine-tests/src/benches/eth_transfer.rs index 3c9f5e750..fc3b56677 100644 --- a/engine-tests/src/benches/eth_transfer.rs +++ b/engine-tests/src/benches/eth_transfer.rs @@ -2,14 +2,14 @@ use criterion::{BatchSize, Criterion}; use libsecp256k1::SecretKey; use crate::prelude::Wei; -use crate::test_utils::{address_from_secret_key, create_eth_transaction, deploy_evm, SUBMIT}; +use crate::utils::{address_from_secret_key, create_eth_transaction, deploy_runner, SUBMIT}; const INITIAL_BALANCE: Wei = Wei::new_u64(1000); const INITIAL_NONCE: u64 = 0; const TRANSFER_AMOUNT: Wei = Wei::new_u64(123); pub fn eth_transfer_benchmark(c: &mut Criterion) { - let mut runner = deploy_evm(); + let mut runner = deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); runner.create_address( diff --git a/engine-tests/src/benches/nft_pagination.rs b/engine-tests/src/benches/nft_pagination.rs index cf366786c..ab4e9d92c 100644 --- a/engine-tests/src/benches/nft_pagination.rs +++ b/engine-tests/src/benches/nft_pagination.rs @@ -1,5 +1,5 @@ use crate::prelude::{Address, Wei, U256}; -use crate::test_utils::{self, solidity}; +use crate::utils::{self, solidity}; use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::parameters::engine::TransactionStatus; use libsecp256k1::SecretKey; @@ -44,7 +44,7 @@ pub fn measure_gas_usage(total_tokens: usize, data_size: usize, tokens_per_page: let nonce = source_account.nonce; let tx = marketplace.get_page(tokens_per_page, 0, nonce.into()); let (status, profile) = runner - .profiled_view_call(&test_utils::as_view_call(tx, dest_address)) + .profiled_view_call(&utils::as_view_call(tx, dest_address)) .unwrap(); assert!(matches!(status, TransactionStatus::Succeed(_))); @@ -157,15 +157,15 @@ impl MarketPlace { } } -fn initialize_evm() -> (test_utils::AuroraRunner, test_utils::Signer, Address) { +fn initialize_evm() -> (utils::AuroraRunner, utils::Signer, Address) { // set up Aurora runner and accounts - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); runner.create_address(source_address, INITIAL_BALANCE, INITIAL_NONCE.into()); - let dest_address = test_utils::address_from_secret_key(&SecretKey::random(&mut rng)); - let mut signer = test_utils::Signer::new(source_account); + let dest_address = utils::address_from_secret_key(&SecretKey::random(&mut rng)); + let mut signer = utils::Signer::new(source_account); signer.nonce = INITIAL_NONCE; runner.wasm_config.limit_config.max_gas_burnt = u64::MAX; diff --git a/engine-tests/src/benches/uniswap.rs b/engine-tests/src/benches/uniswap.rs index b25f2ba54..3f5c3f663 100644 --- a/engine-tests/src/benches/uniswap.rs +++ b/engine-tests/src/benches/uniswap.rs @@ -1,8 +1,8 @@ use criterion::{BatchSize, BenchmarkId, Criterion}; use crate::prelude::U256; -use crate::test_utils::{self, SUBMIT}; use crate::tests::uniswap::UniswapTestContext; +use crate::utils::{self, SUBMIT}; const MINT_AMOUNT: u64 = 1_000_000_000; const LIQUIDITY_AMOUNT: u64 = MINT_AMOUNT / 2; @@ -24,7 +24,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) { let nonce = context.signer.use_nonce(); let liquidity_params = context.mint_params(LIQUIDITY_AMOUNT.into(), &token_a, &token_b); let tx = context.manager.mint(&liquidity_params, nonce.into()); - let signed_tx = test_utils::sign_transaction(tx, chain_id, &context.signer.secret_key); + let signed_tx = utils::sign_transaction(tx, chain_id, &context.signer.secret_key); let liquidity_tx_bytes = rlp::encode(&signed_tx).to_vec(); // create transaction for swapping @@ -34,7 +34,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) { let tx = context .swap_router .exact_output_single(&swap_params, nonce.into()); - let signed_tx = test_utils::sign_transaction(tx, chain_id, &context.signer.secret_key); + let signed_tx = utils::sign_transaction(tx, chain_id, &context.signer.secret_key); let swap_tx_bytes = rlp::encode(&signed_tx).to_vec(); let mut group = c.benchmark_group(&context.name); @@ -63,7 +63,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) { .call(SUBMIT, calling_account_id, liquidity_tx_bytes.clone()); let output = result.unwrap(); let gas = output.burnt_gas; - let eth_gas = test_utils::parse_eth_gas(&output); + let eth_gas = utils::parse_eth_gas(&output); // TODO(#45): capture this in a file println!("UNISWAP_ADD_LIQUIDITY NEAR GAS: {gas:?}"); println!("UNISWAP_ADD_LIQUIDITY ETH GAS: {eth_gas:?}"); @@ -75,7 +75,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) { .call(SUBMIT, calling_account_id, swap_tx_bytes.clone()) .unwrap(); let gas = output.burnt_gas; - let eth_gas = test_utils::parse_eth_gas(&output); + let eth_gas = utils::parse_eth_gas(&output); // TODO(#45): capture this in a file println!("UNISWAP_SWAP NEAR GAS: {gas:?}"); println!("UNISWAP_SWAP ETH GAS: {eth_gas:?}"); diff --git a/engine-tests/src/lib.rs b/engine-tests/src/lib.rs index 41970d34f..9df0f93df 100644 --- a/engine-tests/src/lib.rs +++ b/engine-tests/src/lib.rs @@ -5,6 +5,6 @@ mod benches; #[cfg(test)] mod prelude; #[cfg(test)] -mod test_utils; -#[cfg(test)] mod tests; +#[cfg(test)] +mod utils; diff --git a/engine-tests/src/prelude.rs b/engine-tests/src/prelude.rs index 9c36fdfa5..15525645d 100644 --- a/engine-tests/src/prelude.rs +++ b/engine-tests/src/prelude.rs @@ -10,7 +10,6 @@ mod v0 { pub use aurora_engine_types::storage; pub use aurora_engine_types::types::*; pub use aurora_engine_types::*; - pub use borsh::{BorshDeserialize, BorshSerialize}; } pub use v0::*; diff --git a/engine-tests/src/tests/access_lists.rs b/engine-tests/src/tests/access_lists.rs deleted file mode 100644 index 88de5c76d..000000000 --- a/engine-tests/src/tests/access_lists.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::prelude::transactions::eip_2930::{self, AccessTuple, Transaction2930}; -use crate::prelude::transactions::EthTransactionKind; -use crate::prelude::Wei; -use crate::prelude::{H256, U256}; -use crate::test_utils; -use std::convert::TryFrom; -use std::iter; - -// Test taken from https://github.com/ethereum/tests/blob/develop/GeneralStateTests/stExample/accessListExample.json -// TODO(#170): generally support Ethereum tests -#[test] -fn test_access_list_tx_encoding_decoding() { - let secret_key = libsecp256k1::SecretKey::parse_slice( - &hex::decode("45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8").unwrap(), - ) - .unwrap(); - let transaction = Transaction2930 { - chain_id: 1, - nonce: U256::zero(), - gas_price: U256::from(0x0a), - gas_limit: U256::from(0x061a80), - to: Some(test_utils::address_from_hex( - "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", - )), - value: Wei::new_u64(0x0186a0), - data: vec![0], - access_list: vec![ - AccessTuple { - address: test_utils::address_from_hex("0x095e7baea6a6c7c4c2dfeb977efac326af552d87") - .raw(), - storage_keys: vec![H256::zero(), one()], - }, - AccessTuple { - address: test_utils::address_from_hex("0x195e7baea6a6c7c4c2dfeb977efac326af552d87") - .raw(), - storage_keys: vec![H256::zero()], - }, - ], - }; - - let signed_tx = test_utils::sign_access_list_transaction(transaction, &secret_key); - let bytes: Vec = iter::once(eip_2930::TYPE_BYTE) - .chain(rlp::encode(&signed_tx).into_iter()) - .collect(); - let expected_bytes = hex::decode("01f8f901800a83061a8094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a000f893f85994095e7baea6a6c7c4c2dfeb977efac326af552d87f842a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001f794195e7baea6a6c7c4c2dfeb977efac326af552d87e1a0000000000000000000000000000000000000000000000000000000000000000080a011c97e0bb8a356fe4f49b37863d059c6fe8cd3214a6ac06a8387a2f6f0b75f60a0212368a1097da30806edfd13d9c35662e1baee939235eb25de867980bd0eda26").unwrap(); - - assert_eq!(bytes, expected_bytes); - - let decoded_tx = match EthTransactionKind::try_from(expected_bytes.as_slice()) { - Ok(EthTransactionKind::Eip2930(tx)) => tx, - Ok(_) => panic!("Unexpected transaction type"), - Err(e) => panic!("Transaction parsing failed: {e:?}"), - }; - - assert_eq!(signed_tx, decoded_tx); - - assert_eq!( - signed_tx.sender().unwrap(), - test_utils::address_from_secret_key(&secret_key) - ); -} - -const fn one() -> H256 { - let mut x = [0u8; 32]; - x[31] = 1; - H256(x) -} diff --git a/engine-tests/src/tests/account_id_precompiles.rs b/engine-tests/src/tests/account_id_precompiles.rs index 54679d6b3..6f21a86cd 100644 --- a/engine-tests/src/tests/account_id_precompiles.rs +++ b/engine-tests/src/tests/account_id_precompiles.rs @@ -1,16 +1,16 @@ -use crate::test_utils::{self, standalone}; +use crate::utils::{self, standalone}; use aurora_engine::parameters::SubmitResult; #[test] fn test_account_id_precompiles() { - let mut signer = test_utils::Signer::random(); - let mut runner = test_utils::deploy_evm(); + let mut signer = utils::Signer::random(); + let mut runner = utils::deploy_runner(); let mut standalone = standalone::StandaloneRunner::default(); standalone.init_evm(); runner.standalone_runner = Some(standalone); - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "AccountIds.sol", @@ -43,10 +43,8 @@ fn test_account_id_precompiles() { // confirm the precompile works in view calls too let tx = contract.call_method_without_args("predecessorAccountId", 0.into()); - let sender = test_utils::address_from_secret_key(&signer.secret_key); - let result = runner - .view_call(&test_utils::as_view_call(tx, sender)) - .unwrap(); + let sender = utils::address_from_secret_key(&signer.secret_key); + let result = runner.view_call(&utils::as_view_call(tx, sender)).unwrap(); assert!(result.is_ok()); // double check the case where account_id is the full 64 bytes @@ -71,7 +69,7 @@ fn test_account_id_precompiles() { } fn unwrap_ethabi_string(result: &SubmitResult) -> String { - let bytes = test_utils::unwrap_success_slice(result); + let bytes = utils::unwrap_success_slice(result); let mut tokens = ethabi::decode(&[ethabi::ParamType::String], bytes).unwrap(); tokens.pop().unwrap().into_string().unwrap() } diff --git a/engine-tests/src/tests/contract_call.rs b/engine-tests/src/tests/contract_call.rs index b4d5f4d43..d061059f5 100644 --- a/engine-tests/src/tests/contract_call.rs +++ b/engine-tests/src/tests/contract_call.rs @@ -1,15 +1,15 @@ use crate::prelude::{parameters::SubmitResult, vec, Address, Wei, H256, U256}; -use crate::test_utils::{AuroraRunner, Signer, ORIGIN}; - -use crate::test_utils; -use crate::test_utils::exit_precompile::{Tester, TesterConstructor, DEST_ACCOUNT, DEST_ADDRESS}; +use crate::utils::solidity::exit_precompile::{ + Tester, TesterConstructor, DEST_ACCOUNT, DEST_ADDRESS, +}; +use crate::utils::{self, AuroraRunner, Signer, ORIGIN}; fn setup_test() -> (AuroraRunner, Signer, Address, Tester) { let mut runner = AuroraRunner::new(); let token = runner.deploy_erc20_token("tt.testnet"); - let mut signer = test_utils::Signer::random(); + let mut signer = Signer::random(); runner.create_address( - test_utils::address_from_secret_key(&signer.secret_key), + utils::address_from_secret_key(&signer.secret_key), Wei::from_eth(1.into()).unwrap(), U256::zero(), ); @@ -211,7 +211,7 @@ fn withdraw_eth() { ]; let exit_events = parse_exit_events(result, &schema); - assert!(exit_events.len() == 1); + assert_eq!(exit_events.len(), 1); assert_eq!(&expected_event, &exit_events[0].params); // exit to ethereum @@ -230,7 +230,7 @@ fn withdraw_eth() { let schema = aurora_engine_precompiles::native::events::exit_to_eth_schema(); let exit_events = parse_exit_events(result, &schema); - assert!(exit_events.len() == 1); + assert_eq!(exit_events.len(), 1); assert_eq!(&expected_event, &exit_events[0].params); } diff --git a/engine-tests/src/tests/ecrecover.rs b/engine-tests/src/tests/ecrecover.rs index d2ac8e2e2..47fb78292 100644 --- a/engine-tests/src/tests/ecrecover.rs +++ b/engine-tests/src/tests/ecrecover.rs @@ -1,7 +1,7 @@ use super::sanity::initialize_transfer; use crate::prelude::{make_address, Address, U256}; use crate::prelude::{Wei, H160}; -use crate::test_utils::{self, AuroraRunner, Signer}; +use crate::utils::{self, AuroraRunner, Signer}; use aurora_engine_precompiles::Precompile; const ECRECOVER_ADDRESS: Address = make_address(0, 1); @@ -79,10 +79,7 @@ fn check_wasm_ecrecover( } }) .unwrap(); - assert_eq!( - expected_output, - test_utils::unwrap_success_slice(&wasm_result), - ); + assert_eq!(expected_output, utils::unwrap_success_slice(&wasm_result),); } fn construct_input(hash: &[u8], sig: &[u8]) -> Vec { diff --git a/engine-tests/src/tests/erc20.rs b/engine-tests/src/tests/erc20.rs index 91455f07d..bcb373d23 100644 --- a/engine-tests/src/tests/erc20.rs +++ b/engine-tests/src/tests/erc20.rs @@ -1,8 +1,8 @@ use crate::prelude::Wei; use crate::prelude::{Address, U256}; -use crate::test_utils::{ +use crate::utils::{ self, - erc20::{ERC20Constructor, ERC20}, + solidity::erc20::{self, ERC20Constructor, ERC20}, Signer, }; use aurora_engine::engine::EngineErrorKind; @@ -58,7 +58,7 @@ fn erc20_mint_out_of_gas() { let mut mint_tx = contract.mint(dest_address, mint_amount.into(), nonce.into()); // not enough gas to cover intrinsic cost - let intrinsic_gas = test_utils::erc20::legacy_into_normalized_tx(mint_tx.clone()) + let intrinsic_gas = erc20::legacy_into_normalized_tx(mint_tx.clone()) .intrinsic_gas(&evm::Config::shanghai()) .unwrap(); mint_tx.gas_limit = (intrinsic_gas - 1).into(); @@ -76,13 +76,13 @@ fn erc20_mint_out_of_gas() { // Validate post-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, - test_utils::address_from_secret_key(&source_account.secret_key), + utils::address_from_secret_key(&source_account.secret_key), Wei::new_u64(INITIAL_BALANCE - GAS_LIMIT * GAS_PRICE), (INITIAL_NONCE + 2).into(), ); - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, sdk::types::near_account_to_evm_address( runner.context.predecessor_account_id.as_ref().as_bytes(), @@ -95,7 +95,7 @@ fn erc20_mint_out_of_gas() { #[test] fn profile_erc20_get_balance() { let (mut runner, mut source_account, _, contract) = initialize_erc20(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); let outcome = runner.submit_with_signer(&mut source_account, |nonce| { contract.mint(source_address, INITIAL_BALANCE.into(), nonce) @@ -104,12 +104,12 @@ fn profile_erc20_get_balance() { let balance_tx = contract.balance_of(source_address, U256::zero()); let (status, profile) = runner - .profiled_view_call(&test_utils::as_view_call(balance_tx, source_address)) + .profiled_view_call(&utils::as_view_call(balance_tx, source_address)) .unwrap(); assert!(status.is_ok()); // call costs less than 2 Tgas - test_utils::assert_gas_bound(profile.all_gas(), 2); + utils::assert_gas_bound(profile.all_gas(), 2); // at least 70% of the cost is spent on wasm computation (as opposed to host functions) let wasm_fraction = (100 * profile.wasm_gas()) / profile.all_gas(); assert!( @@ -121,7 +121,7 @@ fn profile_erc20_get_balance() { #[test] fn erc20_transfer_success() { let (mut runner, mut source_account, dest_address, contract) = initialize_erc20(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); let outcome = runner.submit_with_signer(&mut source_account, |nonce| { contract.mint(source_address, INITIAL_BALANCE.into(), nonce) @@ -160,7 +160,7 @@ fn erc20_transfer_success() { #[test] fn erc20_transfer_insufficient_balance() { let (mut runner, mut source_account, dest_address, contract) = initialize_erc20(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); let outcome = runner.submit_with_signer(&mut source_account, |nonce| { contract.mint(source_address, INITIAL_BALANCE.into(), nonce) @@ -183,8 +183,8 @@ fn erc20_transfer_insufficient_balance() { contract.transfer(dest_address, (2 * INITIAL_BALANCE).into(), nonce) }) .unwrap(); - let message = parse_erc20_error_message(&test_utils::unwrap_revert(outcome)); - assert_eq!(&message, "&ERC20: transfer amount exceeds balance"); + let message = parse_erc20_error_message(utils::unwrap_revert_slice(&outcome)); + assert_eq!(message, "&ERC20: transfer amount exceeds balance"); // Validate post-state assert_eq!( @@ -199,10 +199,10 @@ fn erc20_transfer_insufficient_balance() { #[test] fn deploy_erc_20_out_of_gas() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); runner.create_address( source_address, Wei::new_u64(INITIAL_BALANCE), @@ -213,7 +213,7 @@ fn deploy_erc_20_out_of_gas() { let mut deploy_transaction = constructor.deploy("OutOfGas", "OOG", INITIAL_NONCE.into()); // not enough gas to cover intrinsic cost - let intrinsic_gas = test_utils::erc20::legacy_into_normalized_tx(deploy_transaction.clone()) + let intrinsic_gas = erc20::legacy_into_normalized_tx(deploy_transaction.clone()) .intrinsic_gas(&evm::Config::shanghai()) .unwrap(); deploy_transaction.gas_limit = (intrinsic_gas - 1).into(); @@ -229,25 +229,25 @@ fn deploy_erc_20_out_of_gas() { assert_eq!(error.status, TransactionStatus::OutOfGas); // Validate post-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, - test_utils::address_from_secret_key(&source_account), + utils::address_from_secret_key(&source_account), Wei::new_u64(INITIAL_BALANCE), (INITIAL_NONCE + 1).into(), ); } fn get_address_erc20_balance( - runner: &mut test_utils::AuroraRunner, + runner: &mut utils::AuroraRunner, signer: &Signer, address: Address, contract: &ERC20, ) -> U256 { let balance_tx = contract.balance_of(address, signer.nonce.into()); let result = runner - .view_call(&test_utils::as_view_call( + .view_call(&utils::as_view_call( balance_tx, - test_utils::address_from_secret_key(&signer.secret_key), + utils::address_from_secret_key(&signer.secret_key), )) .unwrap(); let bytes = match result { @@ -257,25 +257,25 @@ fn get_address_erc20_balance( U256::from_big_endian(&bytes) } -fn parse_erc20_error_message(result: &[u8]) -> String { +fn parse_erc20_error_message(result: &[u8]) -> &str { let start_index = result.find_char('&').unwrap(); let end_index = result[start_index..].find_byte(0).unwrap() + start_index; - String::from_utf8(result[start_index..end_index].to_vec()).unwrap() + std::str::from_utf8(&result[start_index..end_index]).unwrap() } -fn initialize_erc20() -> (test_utils::AuroraRunner, Signer, Address, ERC20) { +fn initialize_erc20() -> (utils::AuroraRunner, Signer, Address, ERC20) { // set up Aurora runner and accounts - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); runner.create_address( source_address, Wei::new_u64(INITIAL_BALANCE), INITIAL_NONCE.into(), ); - let dest_address = test_utils::address_from_secret_key(&SecretKey::random(&mut rng)); + let dest_address = utils::address_from_secret_key(&SecretKey::random(&mut rng)); let mut signer = Signer::new(source_account); signer.nonce = INITIAL_NONCE; diff --git a/engine-tests/src/tests/erc20_connector.rs b/engine-tests/src/tests/erc20_connector.rs index a09f6d6aa..9bddd2305 100644 --- a/engine-tests/src/tests/erc20_connector.rs +++ b/engine-tests/src/tests/erc20_connector.rs @@ -1,10 +1,10 @@ use crate::prelude::{Address, Balance, Wei, WeiU256, U256}; -use crate::test_utils::{self, create_eth_transaction, AuroraRunner, ORIGIN}; +use crate::utils::{self, create_eth_transaction, AuroraRunner, ORIGIN}; use aurora_engine::engine::EngineError; use aurora_engine::parameters::{CallArgs, FunctionCallArgsV2}; use aurora_engine_transactions::legacy::LegacyEthSignedTransaction; +use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize}; use aurora_engine_types::parameters::engine::{SubmitResult, TransactionStatus}; -use borsh::{BorshDeserialize, BorshSerialize}; use ethabi::Token; use libsecp256k1::SecretKey; use near_vm_logic::VMOutcome; @@ -31,7 +31,7 @@ fn build_input(str_selector: &str, inputs: &[Token]) -> Vec { fn create_ethereum_address() -> Address { let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - test_utils::address_from_secret_key(&source_account) + utils::address_from_secret_key(&source_account) } pub struct EthereumAddress { @@ -41,7 +41,7 @@ pub struct EthereumAddress { impl AuroraRunner { pub fn new() -> Self { - test_utils::deploy_evm() + utils::deploy_runner() } pub fn make_call( @@ -105,7 +105,7 @@ impl AuroraRunner { pub fn create_account(&mut self) -> EthereumAddress { let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); self.create_address(source_address, INITIAL_BALANCE, INITIAL_NONCE.into()); EthereumAddress { secret_key: source_account, @@ -360,42 +360,39 @@ fn test_transfer_erc20_token() { ); } -// Simulation tests for exit to NEAR precompile. -// Note: `AuroraRunner` is not suitable for these tests because -// it does not execute promises; but `near-sdk-sim` does. -pub mod sim_tests { - use crate::prelude::{Wei, WeiU256, U256}; - use crate::test_utils; - use crate::test_utils::erc20::{ERC20Constructor, ERC20}; - use crate::test_utils::exit_precompile::TesterConstructor; - use crate::tests::state_migration::{deploy_evm, AuroraAccount}; - use aurora_engine::parameters::{ - CallArgs, DeployErc20TokenArgs, FunctionCallArgsV2, SubmitResult, +mod workspace { + use super::build_input; + use crate::prelude::{Address, Wei, WeiU256, U256}; + use crate::utils; + use crate::utils::solidity::erc20::ERC20; + use crate::utils::solidity::exit_precompile::TesterConstructor; + use crate::utils::workspace::{ + create_sub_account, deploy_engine, deploy_erc20_from_nep_141, deploy_nep_141, + nep_141_balance_of, transfer_nep_141_to_erc_20, }; - use aurora_engine_types::types::Address; - use borsh::{BorshDeserialize, BorshSerialize}; - use near_sdk_sim::UserAccount; - use serde_json::json; + use aurora_engine::parameters::{CallArgs, FunctionCallArgsV2}; + use aurora_engine_types::parameters::engine::TransactionStatus; + use aurora_engine_workspace::account::Account; + use aurora_engine_workspace::{parse_near, EngineContract, RawContract}; - const FT_PATH: &str = "src/tests/res/fungible_token.wasm"; const FT_TOTAL_SUPPLY: u128 = 1_000_000; const FT_TRANSFER_AMOUNT: u128 = 300_000; const FT_EXIT_AMOUNT: u128 = 100_000; - const FT_ACCOUNT: &str = "test_token.root"; + const FT_ACCOUNT: &str = "test_token"; const INITIAL_ETH_BALANCE: u64 = 777_777_777; const ETH_EXIT_AMOUNT: u64 = 111_111_111; - #[test] - fn test_ghsa_5c82_x4m4_hcj6_exploit() { + #[tokio::test] + async fn test_ghsa_5c82_x4m4_hcj6_exploit() { let TestExitToNearEthContext { mut signer, signer_address, chain_id, tester_address: _, aurora, - } = test_exit_to_near_eth_common(); + } = test_exit_to_near_eth_common().await.unwrap(); - let constructor = test_utils::solidity::ContractConstructor::force_compile( + let constructor = utils::solidity::ContractConstructor::force_compile( "src/tests/res", "target/solidity_build", "exploit.sol", @@ -403,53 +400,54 @@ pub mod sim_tests { ); let nonce = signer.use_nonce().into(); let deploy_tx = constructor.deploy_without_constructor(nonce); - let signed_tx = test_utils::sign_transaction(deploy_tx, Some(chain_id), &signer.secret_key); - let deploy_result = aurora.call("submit", &rlp::encode(&signed_tx)); - let contract_address = match &deploy_result.status() { - near_sdk_sim::transaction::ExecutionStatus::SuccessValue(bytes) => { - let submit_result = SubmitResult::try_from_slice(bytes).unwrap(); - Address::try_from_slice(test_utils::unwrap_success_slice(&submit_result)).unwrap() - } - _ => panic!("Unknown result: {deploy_result:?}"), - }; + let signed_tx = utils::sign_transaction(deploy_tx, Some(chain_id), &signer.secret_key); + let deploy_result = aurora + .submit(rlp::encode(&signed_tx).to_vec()) + .max_gas() + .transact() + .await + .unwrap(); + let contract_address = + if let TransactionStatus::Succeed(bytes) = &deploy_result.value().status { + Address::try_from_slice(bytes).unwrap() + } else { + panic!("Unknown result: {deploy_result:?}"); + }; let contract = constructor.deployed_at(contract_address); - let nonce = signer.use_nonce().into(); let hacker_account = "hacker.near"; - let hacker_account_bytes = hacker_account.as_bytes().to_vec(); let mut exploit_tx = contract.call_method_with_args( "exploit", - &[ethabi::Token::Bytes(hacker_account_bytes)], + &[ethabi::Token::Bytes(hacker_account.as_bytes().to_vec())], nonce, ); exploit_tx.value = Wei::new_u64(ETH_EXIT_AMOUNT); - let signed_tx = - test_utils::sign_transaction(exploit_tx, Some(chain_id), &signer.secret_key); - aurora - .call("submit", &rlp::encode(&signed_tx)) - .assert_success(); + let signed_tx = utils::sign_transaction(exploit_tx, Some(chain_id), &signer.secret_key); + let result = aurora + .submit(rlp::encode(&signed_tx).to_vec()) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); // check balances -- Hacker does not steal any funds! assert_eq!( - nep_141_balance_of( - aurora.contract.account_id.as_str(), - &aurora.contract, - &aurora, - ), + nep_141_balance_of(aurora.as_raw_contract(), &aurora.id()).await, u128::from(INITIAL_ETH_BALANCE) ); assert_eq!( - nep_141_balance_of(hacker_account, &aurora.contract, &aurora), + nep_141_balance_of(aurora.as_raw_contract(), &hacker_account.parse().unwrap()).await, 0 ); assert_eq!( - eth_balance_of(signer_address, &aurora), + eth_balance_of(signer_address, &aurora).await, Wei::new_u64(INITIAL_ETH_BALANCE) ); } - #[test] - fn test_exit_to_near() { + #[tokio::test] + async fn test_exit_to_near() { // Deploy Aurora; deploy NEP-141; bridge NEP-141 to ERC-20 on Aurora let TestExitToNearContext { ft_owner, @@ -457,33 +455,34 @@ pub mod sim_tests { nep_141, erc20, aurora, - } = test_exit_to_near_common(); + } = test_exit_to_near_common().await.unwrap(); // Call exit function on ERC-20; observe ERC-20 burned + NEP-141 transferred exit_to_near( &ft_owner, - ft_owner.account_id.as_str(), + ft_owner.id().as_ref(), FT_EXIT_AMOUNT, &erc20, &aurora, - ); + ) + .await; assert_eq!( - nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &ft_owner.id()).await, FT_TOTAL_SUPPLY - FT_TRANSFER_AMOUNT + FT_EXIT_AMOUNT ); assert_eq!( - nep_141_balance_of(aurora.contract.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &aurora.id()).await, FT_TRANSFER_AMOUNT - FT_EXIT_AMOUNT ); assert_eq!( - erc20_balance(&erc20, ft_owner_address, &aurora), + erc20_balance(&erc20, ft_owner_address, &aurora).await, (FT_TRANSFER_AMOUNT - FT_EXIT_AMOUNT).into() ); } - #[test] - fn test_exit_to_near_refund() { + #[tokio::test] + async fn test_exit_to_near_refund() { // Deploy Aurora; deploy NEP-141; bridge NEP-141 to ERC-20 on Aurora let TestExitToNearContext { ft_owner, @@ -491,7 +490,7 @@ pub mod sim_tests { nep_141, erc20, aurora, - } = test_exit_to_near_common(); + } = test_exit_to_near_common().await.unwrap(); // Call exit on ERC-20; ft_transfer promise fails; expect refund on Aurora; exit_to_near( @@ -501,77 +500,79 @@ pub mod sim_tests { FT_EXIT_AMOUNT, &erc20, &aurora, - ); + ) + .await; assert_eq!( - nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &ft_owner.id()).await, FT_TOTAL_SUPPLY - FT_TRANSFER_AMOUNT ); assert_eq!( - nep_141_balance_of(aurora.contract.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &aurora.id()).await, FT_TRANSFER_AMOUNT ); + #[cfg(feature = "error_refund")] - assert_eq!( - erc20_balance(&erc20, ft_owner_address, &aurora), - FT_TRANSFER_AMOUNT.into() - ); + let balance = FT_TRANSFER_AMOUNT.into(); // If the refund feature is not enabled then there is no refund in the EVM #[cfg(not(feature = "error_refund"))] + let balance = (FT_TRANSFER_AMOUNT - FT_EXIT_AMOUNT).into(); + assert_eq!( - erc20_balance(&erc20, ft_owner_address, &aurora), - (FT_TRANSFER_AMOUNT - FT_EXIT_AMOUNT).into() + erc20_balance(&erc20, ft_owner_address, &aurora).await, + balance ); } - #[test] - fn test_exit_to_near_eth() { + #[tokio::test] + async fn test_exit_to_near_eth() { // Same test as above, but exit ETH instead of a bridged NEP-141 - let TestExitToNearEthContext { signer, signer_address, chain_id, tester_address, aurora, - } = test_exit_to_near_eth_common(); + } = test_exit_to_near_eth_common().await.unwrap(); let exit_account_id = "any.near"; // call exit to near - let input = super::build_input( + let input = build_input( "withdrawEthToNear(bytes)", &[ethabi::Token::Bytes(exit_account_id.as_bytes().to_vec())], ); - let tx = test_utils::create_eth_transaction( + let tx = utils::create_eth_transaction( Some(tester_address), Wei::new_u64(ETH_EXIT_AMOUNT), input, Some(chain_id), &signer.secret_key, ); - aurora.call("submit", &rlp::encode(&tx)).assert_success(); + let result = aurora + .submit(rlp::encode(&tx).to_vec()) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); // check balances assert_eq!( - nep_141_balance_of( - aurora.contract.account_id.as_str(), - &aurora.contract, - &aurora, - ), + nep_141_balance_of(aurora.as_raw_contract(), &aurora.id()).await, u128::from(INITIAL_ETH_BALANCE - ETH_EXIT_AMOUNT) ); assert_eq!( - nep_141_balance_of(exit_account_id, &aurora.contract, &aurora), + nep_141_balance_of(aurora.as_raw_contract(), &exit_account_id.parse().unwrap()).await, u128::from(ETH_EXIT_AMOUNT) ); assert_eq!( - eth_balance_of(signer_address, &aurora), + eth_balance_of(signer_address, &aurora).await, Wei::new_u64(INITIAL_ETH_BALANCE - ETH_EXIT_AMOUNT) ); } - #[test] - fn test_exit_to_near_eth_refund() { + #[tokio::test] + async fn test_exit_to_near_eth_refund() { // Test the case where the ft_transfer promise from the exit call fails; // ensure ETH is refunded. @@ -581,180 +582,177 @@ pub mod sim_tests { chain_id, tester_address, aurora, - } = test_exit_to_near_eth_common(); - let exit_account_id = "any.near".to_owned(); + } = test_exit_to_near_eth_common().await.unwrap(); + let exit_account_id = "any.near"; // Make the ft_transfer call fail by draining the Aurora account - let transfer_args = json!({ - "receiver_id": "tmp.near", - "amount": format!("{INITIAL_ETH_BALANCE}"), - "memo": "null", - }); - aurora - .contract - .call( - aurora.contract.account_id(), - "ft_transfer", - transfer_args.to_string().as_bytes(), - near_sdk_sim::DEFAULT_GAS, - 1, + let result = aurora + .ft_transfer( + &"tmp.near".parse().unwrap(), + u128::from(INITIAL_ETH_BALANCE).into(), + None, ) - .assert_success(); + .max_gas() + .deposit(1) + .transact() + .await + .unwrap(); + assert!(result.is_success()); // call exit to near - let input = super::build_input( + let input = build_input( "withdrawEthToNear(bytes)", &[ethabi::Token::Bytes(exit_account_id.as_bytes().to_vec())], ); - let tx = test_utils::create_eth_transaction( + let tx = utils::create_eth_transaction( Some(tester_address), Wei::new_u64(ETH_EXIT_AMOUNT), input, Some(chain_id), &signer.secret_key, ); - aurora.call("submit", &rlp::encode(&tx)).assert_success(); + let result = aurora + .submit(rlp::encode(&tx).to_vec()) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); // check balances assert_eq!( - nep_141_balance_of(exit_account_id.as_str(), &aurora.contract, &aurora), + nep_141_balance_of(aurora.as_raw_contract(), &exit_account_id.parse().unwrap()).await, 0 ); + #[cfg(feature = "error_refund")] - assert_eq!( - eth_balance_of(signer_address, &aurora), - Wei::new_u64(INITIAL_ETH_BALANCE) - ); + let expected_balance = Wei::new_u64(INITIAL_ETH_BALANCE); // If the refund feature is not enabled then there is no refund in the EVM #[cfg(not(feature = "error_refund"))] + let expected_balance = Wei::new_u64(INITIAL_ETH_BALANCE - ETH_EXIT_AMOUNT); + assert_eq!( - eth_balance_of(signer_address, &aurora), - Wei::new_u64(INITIAL_ETH_BALANCE - ETH_EXIT_AMOUNT) + eth_balance_of(signer_address, &aurora).await, + expected_balance ); } - fn test_exit_to_near_eth_common() -> TestExitToNearEthContext { - let aurora = deploy_evm(); - let chain_id = test_utils::AuroraRunner::default().chain_id; - let signer = test_utils::Signer::random(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); - aurora - .call( - "mint_account", - &(signer_address, signer.nonce, INITIAL_ETH_BALANCE) - .try_to_vec() - .unwrap(), - ) - .assert_success(); + async fn test_exit_to_near_eth_common() -> anyhow::Result { + let aurora = deploy_engine().await; + let chain_id = aurora.get_chain_id().await?.result.as_u64(); + let signer = utils::Signer::random(); + let signer_address = utils::address_from_secret_key(&signer.secret_key); - assert_eq!( - nep_141_balance_of( - aurora.contract.account_id.as_str(), - &aurora.contract, - &aurora, - ), - u128::from(INITIAL_ETH_BALANCE) - ); - assert_eq!( - eth_balance_of(signer_address, &aurora), - Wei::new_u64(INITIAL_ETH_BALANCE) - ); + let result = aurora + .mint_account(signer_address, signer.nonce, INITIAL_ETH_BALANCE) + .max_gas() + .transact() + .await?; + assert!(result.is_success()); + + let balance = aurora.ft_balance_of(&aurora.id()).await?.result; + assert_eq!(balance.0, u128::from(INITIAL_ETH_BALANCE)); + + let balance = eth_balance_of(signer_address, &aurora).await; + assert_eq!(balance, Wei::new_u64(INITIAL_ETH_BALANCE)); // deploy contract with simple exit to near method let constructor = TesterConstructor::load(); let deploy_data = constructor.deploy(0, Address::zero()).data; - let submit_result = match aurora.call("deploy_code", &deploy_data).status() { - near_sdk_sim::transaction::ExecutionStatus::SuccessValue(bytes) => { - SubmitResult::try_from_slice(&bytes).unwrap() - } - other => panic!("Unexpected status {other:?}"), + let result = aurora + .deploy_code(deploy_data) + .max_gas() + .transact() + .await? + .into_value(); + let tester_address = if let TransactionStatus::Succeed(bytes) = result.status { + Address::try_from_slice(&bytes).unwrap() + } else { + anyhow::bail!("Wrong submit result: {result:?}"); }; - let tester_address = - Address::try_from_slice(&test_utils::unwrap_success(submit_result)).unwrap(); - TestExitToNearEthContext { + Ok(TestExitToNearEthContext { signer, signer_address, chain_id, tester_address, aurora, - } + }) } - fn test_exit_to_near_common() -> TestExitToNearContext { + async fn test_exit_to_near_common() -> anyhow::Result { // 1. deploy Aurora - let aurora = deploy_evm(); + let aurora = deploy_engine().await; // 2. Create account - let ft_owner = aurora.user.create_user( - "ft_owner.root".parse().unwrap(), - near_sdk_sim::STORAGE_AMOUNT, - ); + let ft_owner = create_sub_account(&aurora.root(), "ft_owner", parse_near!("50 N")).await?; let ft_owner_address = - aurora_engine_sdk::types::near_account_to_evm_address(ft_owner.account_id.as_bytes()); - aurora - .call( - "mint_account", - &(ft_owner_address, 0u64, INITIAL_ETH_BALANCE) - .try_to_vec() - .unwrap(), - ) - .assert_success(); - + aurora_engine_sdk::types::near_account_to_evm_address(ft_owner.id().as_bytes()); + let result = aurora + .mint_account(ft_owner_address, 0u64, INITIAL_ETH_BALANCE) + .max_gas() + .transact() + .await?; + assert!(result.is_success()); + + let nep_141_account = + create_sub_account(&aurora.root(), FT_ACCOUNT, parse_near!("50 N")).await?; // 3. Deploy NEP-141 - let nep_141 = deploy_nep_141( - FT_ACCOUNT, - ft_owner.account_id.as_ref(), - FT_TOTAL_SUPPLY, - &aurora, - ); + let nep_141 = deploy_nep_141(&nep_141_account, &ft_owner, FT_TOTAL_SUPPLY, &aurora) + .await + .map_err(|e| anyhow::anyhow!("Couldn't deploy NEP-141: {e}"))?; assert_eq!( - nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &ft_owner.id()).await, FT_TOTAL_SUPPLY ); // 4. Deploy ERC-20 from NEP-141 and bridge value to Aurora - let erc20 = deploy_erc20_from_nep_141(&nep_141, &aurora); + let erc20 = deploy_erc20_from_nep_141(nep_141.id().as_ref(), &aurora) + .await + .map_err(|e| anyhow::anyhow!("Couldn't deploy ERC-20 from NEP-141: {e}"))?; + transfer_nep_141_to_erc_20( &nep_141, &erc20, &ft_owner, - ft_owner_address, + Address::from_array(ft_owner_address.raw().0), FT_TRANSFER_AMOUNT, &aurora, - ); + ) + .await + .unwrap(); assert_eq!( - nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &ft_owner.id()).await, FT_TOTAL_SUPPLY - FT_TRANSFER_AMOUNT ); assert_eq!( - nep_141_balance_of(aurora.contract.account_id.as_str(), &nep_141, &aurora), + nep_141_balance_of(&nep_141, &aurora.id()).await, FT_TRANSFER_AMOUNT ); assert_eq!( - erc20_balance(&erc20, ft_owner_address, &aurora), + erc20_balance(&erc20, ft_owner_address, &aurora).await, FT_TRANSFER_AMOUNT.into() ); - TestExitToNearContext { + Ok(TestExitToNearContext { ft_owner, ft_owner_address, nep_141, erc20, aurora, - } + }) } - fn exit_to_near( - source: &UserAccount, + async fn exit_to_near( + source: &Account, dest: &str, amount: u128, erc20: &ERC20, - aurora: &AuroraAccount, + aurora: &EngineContract, ) { - let input = super::build_input( + let input = build_input( "withdrawToNear(bytes,uint256)", &[ ethabi::Token::Bytes(dest.as_bytes().to_vec()), @@ -766,184 +764,49 @@ pub mod sim_tests { value: WeiU256::default(), input, }); - source - .call( - aurora.contract.account_id(), - "call", - &call_args.try_to_vec().unwrap(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - } - - pub fn transfer_nep_141_to_erc_20( - nep_141: &UserAccount, - erc20: &ERC20, - source: &UserAccount, - dest: Address, - amount: u128, - aurora: &AuroraAccount, - ) { - let transfer_args = json!({ - "receiver_id": aurora.contract.account_id.as_str(), - "amount": format!("{amount}"), - "memo": "null", - }); - source - .call( - nep_141.account_id(), - "ft_transfer", - transfer_args.to_string().as_bytes(), - near_sdk_sim::DEFAULT_GAS, - 1, - ) - .assert_success(); - - let mint_tx = erc20.mint(dest, amount.into(), 0.into()); - let call_args = CallArgs::V2(FunctionCallArgsV2 { - contract: erc20.0.address, - value: WeiU256::default(), - input: mint_tx.data, - }); - aurora - .contract - .call( - aurora.contract.account_id(), - "call", - &call_args.try_to_vec().unwrap(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); + let result = source + .call(&aurora.id(), "call") + .args_borsh(call_args) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); } - fn eth_balance_of(address: Address, aurora: &AuroraAccount) -> Wei { - let result = aurora.call("get_balance", address.as_bytes()); - - result.assert_success(); - match result.status() { - near_sdk_sim::transaction::ExecutionStatus::SuccessValue(bytes) => { - Wei::new(U256::from_big_endian(&bytes)) - } - _ => unreachable!(), - } + async fn eth_balance_of(address: Address, aurora: &EngineContract) -> Wei { + let result = aurora.get_balance(address).await.unwrap().result; + Wei::new(result) } - fn erc20_balance(erc20: &ERC20, address: Address, aurora: &AuroraAccount) -> U256 { + async fn erc20_balance(erc20: &ERC20, address: Address, aurora: &EngineContract) -> U256 { let balance_tx = erc20.balance_of(address, 0.into()); - let call_args = CallArgs::V2(FunctionCallArgsV2 { - contract: erc20.0.address, - value: WeiU256::default(), - input: balance_tx.data, - }); - let result = aurora.call("call", &call_args.try_to_vec().unwrap()); - let submit_result = match result.status() { - near_sdk_sim::transaction::ExecutionStatus::SuccessValue(bytes) => { - SubmitResult::try_from_slice(&bytes).unwrap() - } - other => panic!("Unexpected status {other:?}"), - }; - U256::from_big_endian(&test_utils::unwrap_success(submit_result)) - } - - pub fn deploy_erc20_from_nep_141(nep_141: &UserAccount, aurora: &AuroraAccount) -> ERC20 { - let args = DeployErc20TokenArgs { - nep141: nep_141.account_id().as_str().parse().unwrap(), - }; - let result = aurora.call("deploy_erc20_token", &args.try_to_vec().unwrap()); - let addr_bytes: Vec = result.unwrap_borsh(); - let address = Address::try_from_slice(&addr_bytes).unwrap(); - let abi = ERC20Constructor::load().0.abi; - ERC20(test_utils::solidity::DeployedContract { abi, address }) - } - - pub fn nep_141_balance_of( - account_id: &str, - nep_141: &UserAccount, - aurora: &AuroraAccount, - ) -> u128 { - aurora - .user - .call( - nep_141.account_id(), - "ft_balance_of", - json!({ "account_id": account_id }).to_string().as_bytes(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .unwrap_json_value() - .as_str() - .unwrap() - .parse() - .unwrap() - } - - /// Deploys the standard FT implementation: - /// `https://github.com/near/near-sdk-rs/blob/master/examples/fungible-token/ft/src/lib.rs` - pub fn deploy_nep_141( - nep_141_account_id: &str, - token_owner: &str, - amount: u128, - aurora: &AuroraAccount, - ) -> UserAccount { - let contract_bytes = std::fs::read(FT_PATH).unwrap(); - - let contract_account = aurora.user.deploy( - &contract_bytes, - nep_141_account_id.parse().unwrap(), - 5 * near_sdk_sim::STORAGE_AMOUNT, - ); - - let init_args = json!({ - "owner_id": token_owner, - "total_supply": format!("{amount}"), - }) - .to_string(); - - aurora - .user - .call( - contract_account.account_id(), - "new_default_meta", - init_args.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - - // Need to register Aurora contract so that it can receive tokens - let args = json!({ - "account_id": &aurora.contract.account_id, - }) - .to_string(); - aurora - .user - .call( - contract_account.account_id(), - "storage_deposit", - args.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - near_sdk_sim::STORAGE_AMOUNT, - ) - .assert_success(); + let result = aurora + .call(erc20.0.address, U256::zero(), balance_tx.data) + .transact() + .await + .unwrap(); + assert!(result.is_success()); - contract_account + match &result.value().status { + TransactionStatus::Succeed(bytes) => U256::from_big_endian(bytes), + _ => panic!("Unexpected status {result:?}"), + } } struct TestExitToNearContext { - ft_owner: UserAccount, + ft_owner: Account, ft_owner_address: Address, - nep_141: UserAccount, + nep_141: RawContract, erc20: ERC20, - aurora: AuroraAccount, + aurora: EngineContract, } struct TestExitToNearEthContext { - signer: test_utils::Signer, + signer: utils::Signer, signer_address: Address, chain_id: u64, tester_address: Address, - aurora: AuroraAccount, + aurora: EngineContract, } } diff --git a/engine-tests/src/tests/eth_connector.rs b/engine-tests/src/tests/eth_connector.rs index e8dc775f5..e873be8a2 100644 --- a/engine-tests/src/tests/eth_connector.rs +++ b/engine-tests/src/tests/eth_connector.rs @@ -1,21 +1,14 @@ -use crate::prelude::Address; -use crate::prelude::WithdrawCallArgs; -use crate::test_utils::str_to_account_id; -use aurora_engine::admin_controlled::{PausedMask, ERR_PAUSED}; -use aurora_engine::connector::{ - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, PAUSE_DEPOSIT, PAUSE_WITHDRAW, UNPAUSE_ALL, -}; -use aurora_engine::fungible_token::FungibleTokenMetadata; -use aurora_engine::parameters::{ - InitCallArgs, LegacyNewCallArgs, RegisterRelayerCallArgs, WithdrawResult, -}; -use aurora_engine_types::types::{Fee, NEP141Wei}; -use borsh::{BorshDeserialize, BorshSerialize}; -use byte_slice_cast::AsByteSlice; -use ethabi::ethereum_types::U256; -use near_sdk_sim::transaction::ExecutionStatus; -use near_sdk_sim::{to_yocto, ExecutionResult, UserAccount, DEFAULT_GAS, STORAGE_AMOUNT}; +use crate::prelude::{Fee, NEP141Wei, H256, U256}; +use crate::utils::address_from_hex; +use crate::utils::workspace::create_sub_account; +use aurora_engine::connector::{PAUSE_DEPOSIT, PAUSE_WITHDRAW, UNPAUSE_ALL}; +use aurora_engine_types::parameters::connector::Proof; +use aurora_engine_types::parameters::WithdrawCallArgs; +use aurora_engine_types::types::Address; +use aurora_engine_workspace::types::ExecutionOutcome; +use aurora_engine_workspace::{parse_near, EngineContract, EngineContractBuilder}; use serde_json::json; +use std::fmt::Debug; const CONTRACT_ACC: &str = "eth_connector.root"; const PROOF_DATA_NEAR: &str = r#"{"log_index":0,"log_entry_data":[248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,54,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,107,17,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,54,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,177,33,112,26,26,176,12,12,163,2,249,133,245,12,51,201,55,50,148,156,122,67,27,26,101,178,36,153,54,100,53,137,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,197,65,5,202,188,134,5,164,246,19,133,35,57,28,114,241,186,81,123,163,166,161,24,32,157,168,170,13,108,58,61,46,160,6,199,163,13,91,119,225,39,168,255,213,10,107,252,143,246,138,241,108,139,59,35,187,185,162,223,53,108,222,73,181,109,160,27,154,49,63,26,170,15,177,97,255,6,204,84,221,234,197,159,172,114,47,148,126,32,199,241,127,101,120,182,51,52,100,185,1,0,0,0,8,0,0,0,0,0,0,0,32,0,0,0,0,0,2,0,8,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,8,32,0,32,0,0,128,0,2,0,0,0,1,0,32,0,0,0,2,0,0,0,0,32,0,0,0,0,0,4,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,128,64,0,0,0,0,1,32,0,0,0,0,0,0,96,32,0,64,0,0,0,128,1,0,0,0,0,1,0,0,0,8,0,0,0,18,32,0,0,64,145,1,8,0,4,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,16,0,128,0,0,0,0,0,0,128,0,2,0,0,0,0,0,0,0,0,0,0,2,0,80,0,0,0,0,0,0,0,0,1,128,0,8,0,0,0,0,4,0,0,0,128,2,0,32,0,128,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,16,0,8,0,0,0,0,0,0,0,0,0,0,128,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,132,25,1,227,23,131,157,85,14,131,122,18,0,131,75,91,132,132,96,174,58,224,140,115,112,105,100,101,114,49,48,1,2,8,230,160,188,212,199,183,154,22,223,85,103,215,24,122,240,235,79,129,44,93,184,88,161,218,79,5,44,226,106,100,50,40,163,97,136,155,158,202,3,149,91,200,78],"proof":[[248,113,160,46,156,31,85,241,226,241,13,5,56,73,146,176,67,195,109,6,189,172,104,44,103,44,88,32,15,181,152,136,29,121,252,160,191,48,87,174,71,151,208,114,164,150,51,200,171,90,90,106,46,200,79,77,222,145,95,89,141,137,138,149,67,73,8,87,128,128,128,128,128,128,160,175,9,219,77,174,13,247,133,55,172,92,185,202,7,160,10,204,112,44,133,36,96,30,234,235,134,30,209,205,166,212,255,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,107,17,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,54,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; @@ -30,610 +23,346 @@ const EVM_CUSTODIAN_ADDRESS: &str = "096DE9C2B8A5B8c22cEe3289B101f6960d68E51E"; const DEPOSITED_EVM_AMOUNT: u128 = 10200; const DEPOSITED_EVM_FEE: u128 = 200; -#[derive( - Default, BorshDeserialize, BorshSerialize, Clone, serde::Deserialize, serde::Serialize, -)] -pub struct Proof { - pub log_index: u64, - pub log_entry_data: Vec, - pub receipt_index: u64, - pub receipt_data: Vec, - pub header_data: Vec, - pub proof: Vec>, -} - -#[derive(BorshDeserialize, Debug)] -pub struct IsUsedProofResult { - pub is_used_proof: bool, -} - -fn init(custodian_address: &str) -> (UserAccount, UserAccount) { - let master_account = near_sdk_sim::init_simulator(None); - let contract = init_contract(&master_account, CONTRACT_ACC, custodian_address); - (master_account, contract) -} - -fn init_contract( - master_account: &UserAccount, - contract_name: &str, - custodian_address: &str, -) -> UserAccount { - let contract_account = master_account.deploy( - crate::test_utils::AuroraRunner::default().code.code(), - contract_name.parse().unwrap(), - to_yocto("1000000"), - ); - contract_account - .call( - contract_name.parse().unwrap(), - "new", - &LegacyNewCallArgs { - chain_id: [0u8; 32], - owner_id: str_to_account_id(master_account.account_id.clone().as_str()), - bridge_prover_id: str_to_account_id("bridge.prover.near"), - upgrade_delay_blocks: 1, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - STORAGE_AMOUNT, - ) - .assert_success(); - contract_account - .call( - contract_name.parse().unwrap(), - "new_eth_connector", - &InitCallArgs { - prover_account: str_to_account_id(PROVER_ACCOUNT), - eth_custodian_address: custodian_address.into(), - metadata: FungibleTokenMetadata::default(), - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 0, - ) - .assert_success(); - contract_account -} - -fn validate_eth_address(address: &str) -> Address { - Address::decode(address).unwrap() -} - -fn call_deposit_eth_to_near( - master_account: &UserAccount, - contract: &str, -) -> Vec> { - let proof: Proof = serde_json::from_str(PROOF_DATA_NEAR).unwrap(); - let res = master_account.call( - contract.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - //println!("{:#?}", res.promise_results()); - // Calculate Gas burnt - // let total_gas_burnt = res - // .promise_results() - // .iter() - // .fold(0, |s, v| s + v.as_ref().unwrap().gas_burnt()); - // println!("{:#?}", total_gas_burnt); - res.promise_results() -} - -fn call_is_used_proof(account: &UserAccount, contract: &str, proof: &str) -> bool { - let proof: Proof = serde_json::from_str(proof).unwrap(); - let res = account.view( - contract.parse().unwrap(), - "is_used_proof", - &proof.try_to_vec().unwrap(), - ); - let result = IsUsedProofResult::try_from_slice(&res.unwrap()).unwrap(); - result.is_used_proof -} - -fn assert_proof_was_used(account: &UserAccount, contract: &str, proof: &str) { - let is_used_proof = call_is_used_proof(account, contract, proof); - assert!( - is_used_proof, - "{}", - "Expected not to fail because the proof should have been already used", - ); -} - -fn assert_proof_was_not_used(account: &UserAccount, contract: &str, proof: &str) { - let is_used_proof = call_is_used_proof(account, contract, proof); - assert!( - !is_used_proof, - "{}", - "Expected not to fail and to have an unused proof but it was already used", - ); -} - -#[allow(dead_code)] -fn print_logs(logs: &[String]) { - for l in logs { - println!("[log] {l}"); - } -} - -fn call_deposit_eth_to_aurora(master_account: &UserAccount, contract: &str) { - let proof: Proof = serde_json::from_str(PROOF_DATA_ETH).unwrap(); - let res = master_account.call( - contract.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 10, - ); - res.assert_success(); -} - -fn get_eth_on_near_balance(master_account: &UserAccount, acc: &str, contract: &str) -> u128 { - let balance = master_account.view( - contract.parse().unwrap(), - "ft_balance_of", - json!({ "account_id": acc }).to_string().as_bytes(), - ); - let val_str = String::from_utf8(balance.unwrap()).unwrap(); - let val = &val_str[1..val_str.len() - 1]; - val.parse().unwrap() -} - -fn get_eth_balance(master_account: &UserAccount, address: Address, contract: &str) -> u128 { - let balance = master_account.view( - contract.parse().unwrap(), - "ft_balance_of_eth", - &aurora_engine::parameters::BalanceOfEthCallArgs { address } - .try_to_vec() - .unwrap(), - ); - let val_str = String::from_utf8(balance.unwrap()).unwrap(); - let val = &val_str[1..val_str.len() - 1]; - val.parse().unwrap() -} - -fn total_supply(master_account: &UserAccount, contract: &str) -> u128 { - let balance = master_account.view(contract.parse().unwrap(), "ft_total_supply", &[]); - let val_str = String::from_utf8(balance.unwrap()).unwrap(); - let val = &val_str[1..val_str.len() - 1]; - val.parse().unwrap() -} - -fn total_eth_supply_on_near(master_account: &UserAccount, contract: &str) -> u128 { - let balance = master_account.view( - contract.parse().unwrap(), - "ft_total_eth_supply_on_near", - &[], - ); - let val_str = String::from_utf8(balance.unwrap()).unwrap(); - let val = &val_str[1..val_str.len() - 1]; - val.parse().unwrap() -} - -fn total_eth_supply_on_aurora(master_account: &UserAccount, contract: &str) -> u128 { - let balance = master_account.view( - contract.parse().unwrap(), - "ft_total_eth_supply_on_aurora", - &[], - ); - let val_str = String::from_utf8(balance.unwrap()).unwrap(); - let val = &val_str[1..val_str.len() - 1]; - val.parse().unwrap() -} - -#[test] -fn test_deposit_eth_to_near_balance_total_supply() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_deposit_eth_to_near_balance_total_supply() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, 0); } -#[test] -fn test_deposit_eth_to_aurora_balance_total_supply() { - let (master_account, contract) = init(EVM_CUSTODIAN_ADDRESS); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "register_relayer", - &RegisterRelayerCallArgs { - address: validate_eth_address(CUSTODIAN_ADDRESS), - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); +#[tokio::test] +async fn test_deposit_eth_to_aurora_balance_total_supply() { + let contract = init(EVM_CUSTODIAN_ADDRESS).await.unwrap(); + let custodian_address = address_from_hex(CUSTODIAN_ADDRESS); + let res = contract + .register_relayer(custodian_address) + .transact() + .await + .unwrap(); + assert!(res.is_success()); - call_deposit_eth_to_aurora(&contract, CONTRACT_ACC); - assert_proof_was_used(&contract, CONTRACT_ACC, PROOF_DATA_ETH); + call_deposit_eth_to_aurora(&contract).await; + assert_proof_was_used(&contract, PROOF_DATA_ETH).await; - let balance = get_eth_balance( - &master_account, - validate_eth_address(RECIPIENT_ETH_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(RECIPIENT_ETH_ADDRESS)).await; assert_eq!(balance, DEPOSITED_EVM_AMOUNT - DEPOSITED_EVM_FEE); - let balance = get_eth_balance( - &master_account, - validate_eth_address(CUSTODIAN_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, custodian_address).await; assert_eq!(balance, DEPOSITED_EVM_FEE); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_EVM_AMOUNT); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_EVM_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, DEPOSITED_EVM_AMOUNT); } -#[test] -fn test_withdraw_eth_from_near() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); - - let withdraw_amount = NEP141Wei::new(100); - let recipient_addr = validate_eth_address(RECIPIENT_ETH_ADDRESS); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "withdraw", - &WithdrawCallArgs { - recipient_address: recipient_addr, - amount: withdraw_amount, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 1, +#[tokio::test] +async fn test_withdraw_eth_from_near() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); + + let withdraw_amount = 100; + let recipient_addr = address_from_hex(RECIPIENT_ETH_ADDRESS); + let res = contract + .withdraw(recipient_addr, withdraw_amount) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); + let withdraw_result = res.into_value(); + + assert_eq!(withdraw_result.amount.as_u128(), withdraw_amount); + assert_eq!( + withdraw_result.recipient_id.encode(), + recipient_addr.encode() + ); + assert_eq!( + withdraw_result.eth_custodian_address.encode(), + CUSTODIAN_ADDRESS.to_lowercase() ); - res.assert_success(); - let data = res.promise_results(); - assert!(data.len() > 1); - assert!(data[0].is_some()); - match data[1].clone().unwrap().outcome().status { - ExecutionStatus::SuccessValue(ref v) => { - let d: WithdrawResult = WithdrawResult::try_from_slice(v).unwrap(); - assert_eq!(d.amount, withdraw_amount); - assert_eq!(d.recipient_id, recipient_addr); - let custodian_addr = validate_eth_address(CUSTODIAN_ADDRESS); - assert_eq!(d.eth_custodian_address, custodian_addr); - } - _ => panic!(), - } - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); - assert_eq!(balance, DEPOSITED_FEE - withdraw_amount.as_u128()); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; + assert_eq!(balance, DEPOSITED_FEE - withdraw_amount); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = total_supply(&master_account, CONTRACT_ACC); - assert_eq!(balance, DEPOSITED_AMOUNT - withdraw_amount.as_u128()); + let balance = total_supply(&contract).await; + assert_eq!(balance, DEPOSITED_AMOUNT - withdraw_amount); } -#[test] -fn test_ft_transfer() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); - +#[tokio::test] +async fn test_ft_transfer() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); let transfer_amount = 70; - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer", - json!({ - "receiver_id": DEPOSITED_RECIPIENT, - "amount": transfer_amount.to_string(), - "memo": "transfer memo" - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); + let res = contract + .ft_transfer( + &DEPOSITED_RECIPIENT.parse().unwrap(), + transfer_amount.into(), + Some("transfer memo".to_string()), + ) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE + transfer_amount); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE - transfer_amount); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, 0); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); } -#[test] -fn test_ft_transfer_call_eth() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_ft_transfer_call_eth() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "register_relayer", - &RegisterRelayerCallArgs { - address: validate_eth_address(CUSTODIAN_ADDRESS), - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); + let res = contract + .register_relayer(address_from_hex(CUSTODIAN_ADDRESS)) + .transact() + .await + .unwrap(); + assert!(res.is_success()); let transfer_amount = 50; let fee: u128 = 30; - let mut msg = U256::from(fee).as_byte_slice().to_vec(); - msg.append( - &mut validate_eth_address(RECIPIENT_ETH_ADDRESS) - .as_bytes() - .to_vec(), - ); - - let message = [CONTRACT_ACC, hex::encode(msg).as_str()].join(":"); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": CONTRACT_ACC, - "amount": transfer_amount.to_string(), - "msg": message, - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); + let message = create_message(CONTRACT_ACC, RECIPIENT_ETH_ADDRESS, fee); + let res = contract + .ft_transfer_call( + &CONTRACT_ACC.parse().unwrap(), + transfer_amount.into(), + None, + message, + ) + .deposit(1) + .max_gas() + .transact() + .await + .unwrap(); + assert!(res.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let balance = get_eth_balance( - &master_account, - validate_eth_address(RECIPIENT_ETH_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(RECIPIENT_ETH_ADDRESS)).await; assert_eq!(balance, transfer_amount - fee); - let balance = get_eth_balance( - &master_account, - validate_eth_address(CUSTODIAN_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(CUSTODIAN_ADDRESS)).await; assert_eq!(balance, fee); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, transfer_amount); } -#[test] +#[tokio::test] #[allow(clippy::too_many_lines)] -fn test_ft_transfer_call_without_message() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - let recipient_account = create_user_account(&master_account); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +async fn test_ft_transfer_call_without_message() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let contract_account_id = &contract.id(); + let recipient_account = + create_sub_account(&contract.root(), "eth_recipient", parse_near!("50 N")) + .await + .unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "register_relayer", - &RegisterRelayerCallArgs { - address: validate_eth_address(CUSTODIAN_ADDRESS), - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); - - let transfer_amount = 50; - // Send to Aurora contract with wrong message should failed - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": CONTRACT_ACC, - "amount": transfer_amount.to_string(), - "msg": "", - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - match res.outcome().status { - ExecutionStatus::Failure(_) => {} - _ => panic!("Expected execution failure"), - } + let res = contract + .register_relayer(address_from_hex(CUSTODIAN_ADDRESS)) + .transact() + .await + .unwrap(); + assert!(res.is_success()); + + // An attempt to send a message with wrong message format. + let res = contract + .ft_transfer_call( + &CONTRACT_ACC.parse().unwrap(), + 50.into(), + None, + String::new(), + ) + .deposit(1) + .transact() + .await + .err() + .unwrap(); + assert_error_message(&res, "ERR_INVALID_ON_TRANSFER_MESSAGE_FORMAT"); // Assert balances remain unchanged - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - // should revert with `not enough balance` error when sending arbitrary amount while sender_id == receiver_id - let transfer_amount = 1000000000; - let res = recipient_account.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": recipient_account.signer.account_id.to_string(), - "amount": transfer_amount.to_string(), + // Should revert with `NotEnoughBalance` error while sending amount > balance if + // sender_id == receiver_id + let res = recipient_account + .call(contract_account_id, "ft_transfer_call") + .args_json(json!({ + "receiver_id": recipient_account.id(), + "amount": "1000000000", "msg": "", - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - - assert_execution_status_failure( - res.outcome().clone().status, - "ExecutionError(\"Smart contract panicked: ERR_NOT_ENOUGH_BALANCE\")", - "Expected failure in `ft_transfer_call` call, but call succeeded", - ); - - // should not revert with `not enough balance` error when sending arbitrary amount while sender_id == receiver_id with amount < balance - let transfer_amount = 1; - let res = recipient_account.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": recipient_account.signer.account_id.to_string(), - "amount": transfer_amount.to_string(), + })) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_failure()); + assert_error_message(&res.into_result().err().unwrap(), "ERR_NOT_ENOUGH_BALANCE"); + + // Shouldn't revert with `NotEnoughBalance` error while sending amount < balance when + // sender_id == receiver_id + let res = recipient_account + .call(contract_account_id, "ft_transfer_call") + .args_json(json!({ + "receiver_id": recipient_account.id(), + "amount": "1", "msg": "", - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - - res.assert_success(); + })) + .deposit(1) + .max_gas() + .transact() + .await + .unwrap(); + assert!(res.is_success()); // Sending to random account should not change balances let transfer_amount = 22; - let res = recipient_account.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ + let res = recipient_account + .call(contract_account_id, "ft_transfer_call") + .args_json(json!({ "receiver_id": "some-test-acc", "amount": transfer_amount.to_string(), "msg": "", - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); + })) + .max_gas() + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // some-test-acc does not implement `ft_on_transfer` therefore the call fails and the transfer is reverted. - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, "some-test-acc", CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, "some-test-acc").await; assert_eq!(balance, 0); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); // Sending to external receiver with empty message should be success - let dummy_ft_receiver = master_account.deploy( - &dummy_ft_receiver_bytes(), - "ft-rec.root".parse().unwrap(), - STORAGE_AMOUNT, - ); - let res = recipient_account.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": dummy_ft_receiver.account_id(), + let dummy_ft = create_sub_account(&contract.root(), "ft-rec", parse_near!("50 N")) + .await + .unwrap(); + let _result = dummy_ft.deploy(&dummy_ft_receiver_bytes()).await.unwrap(); + + let res = recipient_account + .call(contract_account_id, "ft_transfer_call") + .args_json(json!({ + "receiver_id": dummy_ft.id(), "amount": transfer_amount.to_string(), "msg": "", - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); + })) + .max_gas() + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE - transfer_amount); - let balance = get_eth_on_near_balance( - &master_account, - dummy_ft_receiver.account_id().as_ref(), - CONTRACT_ACC, - ); + + let balance = get_eth_on_near_balance(&contract, dummy_ft.id().as_ref()).await; assert_eq!(balance, transfer_amount); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let balance = get_eth_balance( - &master_account, - validate_eth_address(RECIPIENT_ETH_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(RECIPIENT_ETH_ADDRESS)).await; assert_eq!(balance, 0); - let balance = get_eth_balance( - &master_account, - validate_eth_address(CUSTODIAN_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(CUSTODIAN_ADDRESS)).await; assert_eq!(balance, 0); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, 0); } -#[test] -fn test_deposit_with_0x_prefix() { +#[tokio::test] +async fn test_deposit_with_0x_prefix() { use aurora_engine::deposit_event::TokenMessageData; - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - - let eth_custodian_address: Address = Address::decode(CUSTODIAN_ADDRESS).unwrap(); + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let eth_custodian_address = address_from_hex(CUSTODIAN_ADDRESS); let recipient_address = Address::from_array([10u8; 20]); let deposit_amount = 17; let recipient_address_encoded = recipient_address.encode(); // Note the 0x prefix before the deposit address. let message = [CONTRACT_ACC, ":", "0x", &recipient_address_encoded].concat(); - let fee: Fee = Fee::new(NEP141Wei::new(0)); + let fee: Fee = 0.into(); let token_message_data = TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee) .unwrap(); @@ -656,7 +385,7 @@ fn test_deposit_with_0x_prefix() { topics: vec![ event_schema.signature(), // the sender is not important - crate::prelude::H256::zero(), + H256::zero(), ], data: ethabi::encode(&[ ethabi::Token::String(message), @@ -669,1002 +398,720 @@ fn test_deposit_with_0x_prefix() { // Only this field matters for the purpose of this test log_entry_data: rlp::encode(&log_entry).to_vec(), receipt_index: 1, - receipt_data: Vec::new(), - header_data: Vec::new(), - proof: Vec::new(), + ..Default::default() }; - let res = master_account.call( - contract.account_id(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); - let aurora_balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let aurora_balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(aurora_balance, deposit_amount); - let address_balance = get_eth_balance(&master_account, recipient_address, CONTRACT_ACC); + let address_balance = get_eth_balance(&contract, recipient_address).await; assert_eq!(address_balance, deposit_amount); } -fn generate_dummy_proof(message: String, deposit_amount: u128, log_index: u64) -> Proof { - use aurora_engine::deposit_event::TokenMessageData; - - let eth_custodian_address: Address = Address::decode(CUSTODIAN_ADDRESS).unwrap(); - - let fee: Fee = Fee::new(NEP141Wei::new(0)); - let token_message_data = - TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee) - .unwrap(); - - let deposit_event = aurora_engine::deposit_event::DepositedEvent { - eth_custodian_address, - sender: Address::zero(), - token_message_data, - amount: NEP141Wei::new(deposit_amount), - fee, - }; - - let event_schema = ethabi::Event { - name: aurora_engine::deposit_event::DEPOSITED_EVENT.into(), - inputs: aurora_engine::deposit_event::DepositedEvent::event_params(), - anonymous: false, - }; - let log_entry = aurora_engine_types::parameters::connector::LogEntry { - address: eth_custodian_address.raw(), - topics: vec![ - event_schema.signature(), - // the sender is not important - crate::prelude::H256::zero(), - ], - data: ethabi::encode(&[ - ethabi::Token::String(message), - ethabi::Token::Uint(U256::from(deposit_event.amount.as_u128())), - ethabi::Token::Uint(U256::from(deposit_event.fee.as_u128())), - ]), - }; - - Proof { - log_index, - // Only this field matters for the purpose of this test - log_entry_data: rlp::encode(&log_entry).to_vec(), - receipt_index: 1, - receipt_data: Vec::new(), - header_data: Vec::new(), - proof: Vec::new(), - } -} - -#[test] -fn test_deposit_eth_to_near_account() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - +#[tokio::test] +async fn test_deposit_eth_to_near_account() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); let deposit_amount = 17; + let user_account = create_sub_account(&contract.root(), "some_user", parse_near!("50 N")) + .await + .unwrap(); + let proof = generate_dummy_proof(user_account.id().as_ref(), deposit_amount, 1); - let user_account_id = "some_user.root"; - let _user_account = master_account.create_user( - user_account_id.parse().unwrap(), - to_yocto("100"), // initial balance - ); - let proof = generate_dummy_proof(user_account_id.to_string(), deposit_amount, 1); - - let res = master_account.call( - contract.account_id(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promises = res.promise_results(); - for p in &promises { - assert!(p.is_some()); - let p = p.as_ref().unwrap(); - p.assert_success(); - } - res.assert_success(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); - let aurora_balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let aurora_balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(aurora_balance, 0); - let user_account_balance = - get_eth_on_near_balance(&master_account, user_account_id, CONTRACT_ACC); + let user_account_balance = get_eth_on_near_balance(&contract, user_account.id().as_ref()).await; assert_eq!(user_account_balance, deposit_amount); } -#[test] -fn test_deposit_eth_with_empty_custom_connector_account() { +#[tokio::test] +async fn test_deposit_eth_with_empty_custom_connector_account() { // In this, test we make an ETH deposit using the message format for targeting // an Aurora address, but use a different NEAR account than the Aurora Engine. // The result is that the ETH is correctly minted to the Engine, but then an // error occurs when it tries to transfer those funds because the listed NEAR // account does not implement `ft_on_transfer`. - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); let deposit_amount = 17; - - let user_account_id = "some_user.root"; - let _user_account = master_account.create_user( - user_account_id.parse().unwrap(), - to_yocto("100"), // initial balance - ); - + let user_account = create_sub_account(&contract.root(), "some_user", parse_near!("50 N")) + .await + .unwrap(); let recipient_address = Address::from_array([10u8; 20]); let recipient_address_encoded = recipient_address.encode(); - let message = [user_account_id, ":", "0x", &recipient_address_encoded].concat(); - let proof = generate_dummy_proof(message, deposit_amount, 1); - let res = master_account.call( - contract.account_id(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promises = res.promise_results(); - res.assert_success(); - - let promise = &promises[promises.len() - 5]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - format!( - r#"CompilationError(CodeDoesNotExist {{ account_id: AccountId("{user_account_id}") }}"#, - ) - .as_str(), - "Expected failure in `ft_on_transfer` call, but deposit succeeded", - ); - - let user_account_balance = - get_eth_on_near_balance(&master_account, user_account_id, CONTRACT_ACC); + let message = [ + user_account.id().as_ref(), + ":", + "0x", + &recipient_address_encoded, + ] + .concat(); + let proof = generate_dummy_proof(&message, deposit_amount, 1); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); + + let outcomes = res.outcomes(); + let failure_outcome = outcomes.get(5).unwrap(); + assert!(failure_outcome.is_failure()); + assert_error_message( + &failure_outcome, + r#"FunctionCallError(CompilationError(CodeDoesNotExist { account_id: AccountId("some_user.root") }))"#, + ); + + let user_account_balance = get_eth_on_near_balance(&contract, user_account.id().as_ref()).await; assert_eq!(user_account_balance, 0); - let aurora_balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let aurora_balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(aurora_balance, deposit_amount); - let address_balance = get_eth_balance(&master_account, recipient_address, CONTRACT_ACC); + let address_balance = get_eth_balance(&contract, recipient_address).await; assert_eq!(address_balance, 0); } -#[test] -fn test_deposit_eth_with_custom_connector_account() { +#[tokio::test] +async fn test_deposit_eth_with_custom_connector_account() { // In this test, we make an ETH deposit using the message format for targeting // an Aurora address, but use a different NEAR account than the Aurora Engine. // Additionally, the target account implements `ft_on_transfer` so that it can // receive the ETH and perform some action with it. This is safe because the ETH is // minted in the Engine first, then transferred to the target account using // `ft_transfer_call`. - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); let deposit_amount = 17; - - let user_account_id = "some_user.root"; - let _user_account = master_account.deploy( - &dummy_ft_receiver_bytes(), - user_account_id.parse().unwrap(), - to_yocto("100"), // initial balance - ); + let user_account = create_sub_account(&contract.root(), "some_user", parse_near!("50 N")) + .await + .unwrap(); + let _result = user_account + .deploy(&dummy_ft_receiver_bytes()) + .await + .unwrap(); let recipient_address = Address::from_array([10u8; 20]); - let recipient_address_encoded = recipient_address.encode(); - let message = [user_account_id, ":", "0x", &recipient_address_encoded].concat(); - let proof = generate_dummy_proof(message, deposit_amount, 1); - let res = master_account.call( - contract.account_id(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, + let recipient_address_str = recipient_address.encode(); + let message = [ + user_account.id().as_ref(), + ":", + "0x", + &recipient_address_str, + ] + .concat(); + let proof = generate_dummy_proof(&message, deposit_amount, 1); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); + let outcomes = res.outcomes(); + let outcome = outcomes + .iter() + .find(|o| o.executor_id.as_str() == user_account.id().as_ref()) + .unwrap(); + assert_eq!( + &outcome.logs[0], + "in 17 tokens from @eth_connector.root ft_on_transfer, msg = some_user.root:00000000000000\ + 000000000000000000000000000000000000000000000000000a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a" ); - let promises = res.promise_results(); - for p in &promises { - assert!(p.is_some()); - let p = p.as_ref().unwrap(); - if p.executor_id().as_str() == user_account_id { - // The `ft_on_transfer` implementation in the user's account generates this log. - assert_eq!( - p.logs().first().map(String::as_str), - Some("in 17 tokens from @eth_connector.root ft_on_transfer, msg = some_user.root:00000000000000000000000000000000000000000000000000000000000000000a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a"), - ); - } - p.assert_success(); - } - res.assert_success(); - let user_account_balance = - get_eth_on_near_balance(&master_account, user_account_id, CONTRACT_ACC); + let user_account_balance = get_eth_on_near_balance(&contract, user_account.id().as_ref()).await; assert_eq!(user_account_balance, deposit_amount); - let aurora_balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let aurora_balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(aurora_balance, 0); - let address_balance = get_eth_balance(&master_account, recipient_address, CONTRACT_ACC); + let address_balance = get_eth_balance(&contract, recipient_address).await; assert_eq!(address_balance, 0); } -#[test] -fn test_deposit_with_same_proof() { - let (_master_account, contract) = init(CUSTODIAN_ADDRESS); +#[tokio::test] +async fn test_deposit_with_same_proof() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); - assert_proof_was_not_used(&contract, CONTRACT_ACC, PROOF_DATA_NEAR); + assert_proof_was_not_used(&contract, PROOF_DATA_NEAR).await; - let promises = call_deposit_eth_to_near(&contract, CONTRACT_ACC); - for p in &promises { - assert!(p.is_some()); - let p = p.as_ref().unwrap(); - p.assert_success(); - } + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); - assert_proof_was_used(&contract, CONTRACT_ACC, PROOF_DATA_NEAR); + assert_proof_was_used(&contract, PROOF_DATA_NEAR).await; - let promises = call_deposit_eth_to_near(&contract, CONTRACT_ACC); - let promise = &promises[promises.len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - "ERR_PROOF_EXIST", - "Expected failure as the provided proof already exists, but deposit succeeded", - ); + let result = call_deposit_eth_to_near(&contract).await; + assert!(result.is_err()); + assert_error_message(&result.err().unwrap(), "ERR_PROOF_EXIST"); } -#[test] -fn test_deposit_wrong_custodian_address() { +#[tokio::test] +async fn test_deposit_wrong_custodian_address() { let wrong_custodian_address = "0000000000000000000000000000000000000001"; - let (_master_account, contract) = init(wrong_custodian_address); - let promises = call_deposit_eth_to_near(&contract, CONTRACT_ACC); - let promise = &promises[promises.len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - "ERR_WRONG_EVENT_ADDRESS", - "Expected failure as the provided proof originated from wrong EthCustodian contract, but deposit succeeded", - ); + let contract = init(wrong_custodian_address).await.unwrap(); + let error = call_deposit_eth_to_near(&contract).await.err().unwrap(); - assert_proof_was_not_used(&contract, CONTRACT_ACC, PROOF_DATA_NEAR); + assert_error_message(&error, "ERR_WRONG_EVENT_ADDRESS"); + assert_proof_was_not_used(&contract, PROOF_DATA_NEAR).await; } -#[test] -fn test_ft_transfer_call_without_relayer() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_ft_transfer_call_without_relayer() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let res = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(res.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); let transfer_amount = 50; let fee: u128 = 30; - let mut msg = U256::from(fee).as_byte_slice().to_vec(); - msg.append( - &mut validate_eth_address(RECIPIENT_ETH_ADDRESS) - .as_bytes() - .to_vec(), - ); - let relayer_id = "relayer.root"; - let message = [relayer_id, hex::encode(msg).as_str()].join(":"); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": CONTRACT_ACC, - "amount": transfer_amount.to_string(), - "msg": message, - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); + let message = create_message("relayer.root", RECIPIENT_ETH_ADDRESS, fee); + let res = contract + .ft_transfer_call(&contract.id(), transfer_amount.into(), None, message) + .deposit(1) + .max_gas() + .transact() + .await + .unwrap(); + assert!(res.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let balance = get_eth_balance( - &master_account, - validate_eth_address(RECIPIENT_ETH_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(RECIPIENT_ETH_ADDRESS)).await; assert_eq!(balance, transfer_amount); - let balance = get_eth_balance( - &master_account, - validate_eth_address(CUSTODIAN_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(CUSTODIAN_ADDRESS)).await; assert_eq!(balance, 0); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, transfer_amount); } -#[test] -fn test_ft_transfer_call_fee_greater_than_amount() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_ft_transfer_call_fee_greater_than_amount() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let res = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(res.is_success()); let transfer_amount = 10; let fee: u128 = transfer_amount + 10; - let mut msg = fee.to_be_bytes().to_vec(); - msg.append( - &mut validate_eth_address(RECIPIENT_ETH_ADDRESS) - .as_bytes() - .to_vec(), - ); - let relayer_id = "relayer.root"; - let message = [relayer_id, hex::encode(msg).as_str()].join(":"); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer_call", - json!({ - "receiver_id": CONTRACT_ACC, - "amount": transfer_amount.to_string(), - "msg": message, - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, + let message = create_message("relayer.root", RECIPIENT_ETH_ADDRESS, fee); + let err = contract + .ft_transfer_call(&contract.id(), transfer_amount.into(), None, message) + .deposit(1) + .transact() + .await + .err() + .unwrap(); + assert_error_message( + &err, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", ); - match res.outcome().clone().status { - ExecutionStatus::Failure(_) => {} - _ => panic!(), - } - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE); - let balance = get_eth_balance( - &master_account, - validate_eth_address(RECIPIENT_ETH_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(RECIPIENT_ETH_ADDRESS)).await; assert_eq!(balance, 0); - let balance = get_eth_balance( - &master_account, - validate_eth_address(CUSTODIAN_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(CUSTODIAN_ADDRESS)).await; assert_eq!(balance, 0); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, 0); } -fn call_deposit_with_proof( - account: &UserAccount, - contract: &str, - proof: &str, -) -> Vec> { - let proof: Proof = serde_json::from_str(proof).unwrap(); - let res = account.call( - contract.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - res.promise_results() -} - -fn call_set_paused_flags( - account: &UserAccount, - contract: &str, - paused_mask: PausedMask, -) -> ExecutionResult { - account.call( - contract.parse().unwrap(), - "set_paused_flags", - &paused_mask.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ) -} - -fn create_user_account(master_account: &UserAccount) -> UserAccount { - master_account.create_user( - "eth_recipient.root".parse().unwrap(), - to_yocto("100"), // initial balance - ) -} - -fn validate_promises(promises: Vec>) { - assert!(promises.len() > 1); - - for p in promises { - assert!(p.is_some()); - let p = p.as_ref().unwrap(); - p.assert_success(); - } -} - -#[test] -fn test_admin_controlled_only_admin_can_pause() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - let user_account = create_user_account(&master_account); +#[tokio::test] +async fn test_admin_controlled_only_admin_can_pause() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let user_account = create_sub_account(&contract.root(), "user", parse_near!("50 N")) + .await + .unwrap(); // Try to pause from the user - should fail - let res = call_set_paused_flags(&user_account, CONTRACT_ACC, PAUSE_DEPOSIT); - let promises = res.promise_results(); - let p = promises[1].clone(); - match p.unwrap().outcome().clone().status { - ExecutionStatus::Failure(_) => {} - _ => panic!("Expected failure as only admin can pause, but user successfully paused"), - } + let res = user_account + .call(&contract.id(), "set_paused_flags") + .args_borsh(PAUSE_DEPOSIT) + .transact() + .await + .unwrap(); + assert!(res.is_failure()); // Try to pause from the admin - should succeed - let res = call_set_paused_flags(&contract, CONTRACT_ACC, PAUSE_DEPOSIT); - res.assert_success(); + let res = contract + .set_paused_flags(PAUSE_DEPOSIT) + .transact() + .await + .unwrap(); + assert!(res.is_success()); } -#[test] -fn test_admin_controlled_admin_can_peform_actions_when_paused() { - let (_master_account, contract) = init(CUSTODIAN_ADDRESS); +#[tokio::test] +async fn test_admin_controlled_admin_can_perform_actions_when_paused() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); // 1st deposit call when unpaused - should succeed - let promises = call_deposit_with_proof(&contract, CONTRACT_ACC, PROOF_DATA_NEAR); - validate_promises(promises); + let proof: Proof = serde_json::from_str(PROOF_DATA_NEAR).unwrap(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); - let withdraw_amount = NEP141Wei::new(100); - let recipient_addr = validate_eth_address(RECIPIENT_ETH_ADDRESS); + let withdraw_amount = 100; + let recipient_addr = address_from_hex(RECIPIENT_ETH_ADDRESS); // 1st withdraw call when unpaused - should succeed - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "withdraw", - &WithdrawCallArgs { - recipient_address: recipient_addr, - amount: withdraw_amount, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); - let promises = res.promise_results(); - validate_promises(promises); + let res = contract + .withdraw(recipient_addr, withdraw_amount) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // Pause deposit - let res = call_set_paused_flags(&contract, CONTRACT_ACC, PAUSE_DEPOSIT); - res.assert_success(); + let res = contract + .set_paused_flags(PAUSE_DEPOSIT) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // 2nd deposit call when paused, but the admin is calling it - should succeed // NB: We can use `PROOF_DATA_ETH` this will be just a different proof but the same deposit // method which should be paused - let promises = call_deposit_with_proof(&contract, CONTRACT_ACC, PROOF_DATA_ETH); - validate_promises(promises); + let proof = serde_json::from_str(PROOF_DATA_ETH).unwrap(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); // Pause withdraw - let res = call_set_paused_flags(&contract, CONTRACT_ACC, PAUSE_WITHDRAW); - res.assert_success(); + let res = contract + .set_paused_flags(PAUSE_WITHDRAW) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // 2nd withdraw call when paused, but the admin is calling it - should succeed - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "withdraw", - &WithdrawCallArgs { - recipient_address: recipient_addr, - amount: withdraw_amount, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); - let promises = res.promise_results(); - validate_promises(promises); + let res = contract + .withdraw(recipient_addr, withdraw_amount) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); } -#[test] -fn test_deposit_pausability() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - let user_account = create_user_account(&master_account); +#[tokio::test] +async fn test_deposit_pausability() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let user_account = create_sub_account(&contract.root(), "user", parse_near!("50 N")) + .await + .unwrap(); // 1st deposit call - should succeed - let promises = call_deposit_with_proof(&user_account, CONTRACT_ACC, PROOF_DATA_NEAR); - validate_promises(promises); + let proof: Proof = serde_json::from_str(PROOF_DATA_NEAR).unwrap(); + let res = user_account + .call(&contract.id(), "deposit") + .args_borsh(proof) + .max_gas() + .transact() + .await + .unwrap(); + assert!(res.is_success()); // Pause deposit - let res = call_set_paused_flags(&contract, CONTRACT_ACC, PAUSE_DEPOSIT); - res.assert_success(); + let res = contract + .set_paused_flags(PAUSE_DEPOSIT) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // 2nd deposit call - should fail // NB: We can use `PROOF_DATA_ETH` this will be just a different proof but the same deposit // method which should be paused - let promises = call_deposit_with_proof(&user_account, CONTRACT_ACC, PROOF_DATA_ETH); - let num_promises = promises.len(); - let p = promises[num_promises - 2].clone(); - assert_execution_status_failure( - p.unwrap().outcome().clone().status, - ERR_PAUSED, - "Expected failure due to pause, but deposit succeeded", - ); + let proof: Proof = serde_json::from_str(PROOF_DATA_ETH).unwrap(); + let res = user_account + .call(&contract.id(), "deposit") + .args_borsh(proof) + .max_gas() + .transact() + .await + .unwrap(); + assert!(res.is_failure()); // Unpause all - let res = call_set_paused_flags(&contract, CONTRACT_ACC, UNPAUSE_ALL); - res.assert_success(); + let res = contract + .set_paused_flags(UNPAUSE_ALL) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // 3rd deposit call - should succeed - let promises = call_deposit_with_proof(&user_account, CONTRACT_ACC, PROOF_DATA_ETH); - validate_promises(promises); + let proof: Proof = serde_json::from_str(PROOF_DATA_ETH).unwrap(); + let res = user_account + .call(&contract.id(), "deposit") + .args_borsh(proof) + .max_gas() + .transact() + .await + .unwrap(); + assert!(res.is_success()); } -#[test] -fn test_withdraw_from_near_pausability() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - let user_account = create_user_account(&master_account); - - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_withdraw_from_near_pausability() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let user_account = create_sub_account(&contract.root(), "eth_recipient", parse_near!("50 N")) + .await + .unwrap(); + let res = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(res.is_success()); - let withdraw_amount = NEP141Wei::new(100); - let recipient_addr = validate_eth_address(RECIPIENT_ETH_ADDRESS); + let withdraw_args = WithdrawCallArgs { + recipient_address: address_from_hex(RECIPIENT_ETH_ADDRESS), + amount: NEP141Wei::new(10), + }; // 1st withdraw - should succeed - let res = user_account.call( - CONTRACT_ACC.parse().unwrap(), - "withdraw", - &WithdrawCallArgs { - recipient_address: recipient_addr, - amount: withdraw_amount, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); - let promises = res.promise_results(); - validate_promises(promises); + let res = user_account + .call(&contract.id(), "withdraw") + .args_borsh(withdraw_args.clone()) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // Pause withdraw - let res = call_set_paused_flags(&contract, CONTRACT_ACC, PAUSE_WITHDRAW); - res.assert_success(); + let res = contract + .set_paused_flags(PAUSE_WITHDRAW) + .transact() + .await + .unwrap(); + assert!(res.is_success()); // 2nd withdraw - should fail - let res = user_account.call( - CONTRACT_ACC.parse().unwrap(), - "withdraw", - &WithdrawCallArgs { - recipient_address: recipient_addr, - amount: withdraw_amount, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 1, - ); - let promises = res.promise_results(); - let p = promises[1].clone(); - assert_execution_status_failure( - p.unwrap().outcome().clone().status, - ERR_PAUSED, - "Expected failure due to pause, but withdraw succeeded", - ); + let res = user_account + .call(&contract.id(), "withdraw") + .args_borsh(withdraw_args.clone()) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_failure()); + assert_error_message(&res.into_result().err().unwrap(), "ERR_PAUSED"); // Unpause all - let res = call_set_paused_flags(&contract, CONTRACT_ACC, UNPAUSE_ALL); - res.assert_success(); - - let res = user_account.call( - CONTRACT_ACC.parse().unwrap(), - "withdraw", - &WithdrawCallArgs { - recipient_address: recipient_addr, - amount: withdraw_amount, - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); - let promises = res.promise_results(); - validate_promises(promises); + let res = contract + .set_paused_flags(UNPAUSE_ALL) + .transact() + .await + .unwrap(); + assert!(res.is_success()); + + let res = user_account + .call(&contract.id(), "withdraw") + .args_borsh(withdraw_args) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); } -#[test] -fn test_get_accounts_counter() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_get_accounts_counter() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let res = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(res.is_success()); - let counter = master_account - .view(CONTRACT_ACC.parse().unwrap(), "get_accounts_counter", &[]) - .unwrap(); - assert_eq!(u64::try_from_slice(&counter[..]).unwrap(), 2); + let counter = contract.get_accounts_counter().await.unwrap(); + assert_eq!(counter.result, 2); } -#[test] -fn test_get_accounts_counter_and_transfer() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_get_accounts_counter_and_transfer() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let res = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(res.is_success()); - let counter = master_account - .view(CONTRACT_ACC.parse().unwrap(), "get_accounts_counter", &[]) - .unwrap(); - assert_eq!(u64::try_from_slice(&counter[..]).unwrap(), 2); + let counter = contract.get_accounts_counter().await.unwrap(); + assert_eq!(counter.result, 2); let transfer_amount = 70; - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer", - json!({ - "receiver_id": DEPOSITED_RECIPIENT, - "amount": transfer_amount.to_string(), - "memo": "transfer memo" - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - res.assert_success(); + let res = contract + .ft_transfer( + &DEPOSITED_RECIPIENT.parse().unwrap(), + transfer_amount.into(), + Some("transfer memo".to_string()), + ) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_success()); - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, DEPOSITED_AMOUNT - DEPOSITED_FEE + transfer_amount); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, DEPOSITED_FEE - transfer_amount); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, 0); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, DEPOSITED_AMOUNT); - let counter = master_account - .view(CONTRACT_ACC.parse().unwrap(), "get_accounts_counter", &[]) - .unwrap(); - assert_eq!(u64::try_from_slice(&counter[..]).unwrap(), 2); + let counter = contract.get_accounts_counter().await.unwrap(); + assert_eq!(counter.result, 2); } -#[test] -fn test_deposit_to_near_with_zero_fee() { - let (master_account, contract) = init(CUSTODIAN_ADDRESS); +#[tokio::test] +async fn test_deposit_to_near_with_zero_fee() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,249,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,23,160,7,139,123,21,146,99,81,234,117,153,151,30,67,221,231,90,105,219,121,127,196,224,201,83,178,31,173,155,190,123,227,174,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,109,150,79,199,61,172,73,162,195,49,105,169,235,252,47,207,92,249,136,136,160,227,202,170,144,85,104,169,90,220,93,227,155,76,252,229,223,163,146,127,223,157,121,27,238,116,64,112,216,124,129,107,9,160,158,128,122,7,117,120,186,231,92,224,181,67,43,66,153,79,155,38,238,166,68,1,151,100,134,126,214,86,59,66,174,201,160,235,177,124,164,253,179,174,206,160,196,186,61,51,64,217,35,121,86,229,24,251,162,51,82,72,31,218,240,150,32,157,48,185,1,0,0,0,8,0,0,32,0,0,0,0,0,0,128,0,0,0,2,0,128,0,64,32,0,0,0,0,0,0,64,0,0,10,0,0,0,0,0,0,3,0,0,0,0,64,128,0,0,64,0,0,0,0,0,16,0,0,130,0,1,16,0,32,4,0,0,0,0,0,2,1,0,0,0,0,0,8,0,8,0,0,32,0,4,128,2,0,128,0,0,0,0,0,0,0,0,0,4,32,0,8,2,0,0,0,128,65,0,136,0,0,40,0,0,0,8,0,0,128,0,34,0,4,0,185,2,0,0,4,32,128,0,2,0,0,0,128,0,0,10,0,1,0,1,0,0,0,0,32,1,8,128,0,0,4,0,0,0,128,128,0,70,0,0,0,0,0,0,16,64,0,64,0,34,64,0,0,0,4,0,0,0,0,1,128,0,9,0,0,0,0,0,16,0,0,64,2,0,0,0,132,0,64,32,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,4,0,0,0,32,8,0,16,0,8,0,16,68,0,0,0,16,0,0,0,128,0,64,0,0,128,0,0,0,0,0,0,0,16,0,1,0,16,132,49,181,116,68,131,157,92,101,131,122,18,0,131,101,155,9,132,96,174,110,74,153,216,131,1,10,1,132,103,101,116,104,134,103,111,49,46,49,54,135,119,105,110,100,111,119,115,160,228,82,26,232,236,82,141,6,111,169,92,14,115,254,59,131,192,3,202,209,126,79,140,182,163,12,185,45,210,17,60,38,136,84,114,37,115,236,183,145,213],"proof":[[248,145,160,187,129,186,104,13,250,13,252,114,170,223,247,137,53,113,225,188,217,54,244,108,193,247,236,197,29,0,161,119,76,227,184,160,66,209,234,66,254,223,80,22,246,80,204,38,2,90,115,201,183,79,207,47,192,234,143,221,89,78,36,199,127,9,55,190,160,91,160,251,58,165,255,90,2,105,47,46,220,67,3,52,105,42,182,130,224,19,162,115,159,136,158,218,93,187,148,188,9,128,128,128,128,128,160,181,223,248,223,173,187,103,169,52,204,62,13,90,70,147,236,199,27,201,112,157,4,139,63,188,12,98,117,10,82,85,125,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,249,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); - assert_proof_was_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_used(&contract, proof_str).await; let deposited_amount = 3000; - let balance = get_eth_on_near_balance(&master_account, DEPOSITED_RECIPIENT, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, DEPOSITED_RECIPIENT).await; assert_eq!(balance, deposited_amount); - let balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC); + let balance = get_eth_on_near_balance(&contract, CONTRACT_ACC).await; assert_eq!(balance, 0); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, deposited_amount); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, deposited_amount); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, 0); } -#[test] -fn test_deposit_to_aurora_with_zero_fee() { - let (master_account, contract) = init(EVM_CUSTODIAN_ADDRESS); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "register_relayer", - &RegisterRelayerCallArgs { - address: validate_eth_address(CUSTODIAN_ADDRESS), - } - .try_to_vec() - .unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); +#[tokio::test] +async fn test_deposit_to_aurora_with_zero_fee() { + let contract = init(EVM_CUSTODIAN_ADDRESS).await.unwrap(); + let res = contract + .register_relayer(address_from_hex(CUSTODIAN_ADDRESS)) + .transact() + .await + .unwrap(); + assert!(res.is_success()); let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":3,"receipt_data":[249,2,41,1,131,2,246,200,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,23,160,110,48,40,236,52,198,197,25,255,191,199,4,137,3,185,31,202,84,90,80,104,32,176,13,144,141,165,183,36,30,94,138,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,148,156,193,169,167,156,148,249,191,22,225,202,121,212,79,2,197,75,191,164,160,127,26,168,212,111,22,173,213,25,217,187,227,114,86,173,99,166,195,67,16,104,111,200,109,110,147,241,23,71,122,89,215,160,47,120,179,75,110,158,228,18,242,156,38,111,95,25,236,211,158,53,53,62,89,190,2,40,220,41,151,200,127,219,33,219,160,222,177,165,249,98,109,130,37,226,229,165,113,45,12,145,30,16,28,154,86,22,203,218,233,13,246,165,177,61,57,68,83,185,1,0,0,32,8,0,33,0,0,0,64,0,32,0,128,0,0,0,132,0,0,0,64,32,64,0,0,1,0,32,64,0,0,8,0,0,0,0,0,0,137,32,0,0,0,64,128,0,0,16,0,0,0,0,33,64,0,1,0,0,0,0,0,0,0,0,68,0,0,0,2,1,64,0,0,0,0,9,16,0,0,32,0,0,0,128,2,0,0,0,33,0,0,0,128,0,0,0,12,64,32,8,66,2,0,0,64,0,0,8,0,0,40,8,8,0,0,0,0,16,0,0,0,0,64,49,0,0,8,0,96,0,0,18,0,0,0,0,0,64,10,0,1,0,0,32,0,0,0,33,0,0,128,136,10,64,0,64,0,0,192,128,0,0,64,1,0,0,4,0,8,0,64,0,34,0,0,0,0,0,0,0,0,0,0,0,8,8,0,4,0,0,0,32,0,4,0,2,0,0,0,129,4,0,96,16,4,8,0,0,0,0,0,0,1,0,128,16,0,0,2,0,4,0,32,0,8,0,0,0,0,16,0,1,0,0,0,0,64,0,128,0,0,32,36,128,0,0,4,64,0,8,8,16,0,1,4,16,132,50,32,156,229,131,157,92,137,131,122,18,0,131,35,159,183,132,96,174,111,126,153,216,131,1,10,3,132,103,101,116,104,136,103,111,49,46,49,54,46,51,133,108,105,110,117,120,160,59,74,90,253,211,14,166,114,39,213,120,95,221,43,109,173,72,205,160,203,71,44,83,159,36,59,129,84,32,16,254,251,136,49,16,97,244,161,246,244,85],"proof":[[248,113,160,227,103,29,228,16,56,196,146,115,29,122,202,254,140,214,86,189,108,47,197,2,195,50,211,4,126,58,175,71,11,70,78,160,229,239,23,242,100,150,90,169,21,162,252,207,202,244,187,71,172,126,191,33,166,162,45,134,108,114,6,76,78,177,148,140,128,128,128,128,128,128,160,21,91,249,81,132,162,52,236,128,181,5,72,158,228,177,131,87,144,64,194,111,103,180,16,183,103,245,136,125,213,208,76,128,128,128,128,128,128,128,128],[249,1,241,128,160,52,154,34,8,39,210,121,1,151,92,91,225,198,154,204,207,11,204,187,59,223,154,187,102,115,110,193,141,201,198,95,253,160,218,19,188,241,210,48,51,3,76,125,48,152,171,188,45,136,109,71,236,171,242,162,10,34,245,160,191,5,120,9,80,129,160,147,160,142,184,113,171,112,171,131,124,150,117,65,27,207,149,119,136,120,65,7,99,155,114,169,57,91,125,26,117,49,67,160,173,217,104,114,149,170,18,227,251,73,78,11,220,243,240,66,117,32,199,64,138,173,169,43,8,122,39,47,210,54,41,192,160,139,116,124,73,113,242,225,65,167,48,33,13,149,51,152,196,79,93,126,103,116,48,177,25,80,186,34,55,15,116,2,13,160,67,10,207,13,108,228,254,73,175,10,166,107,144,157,150,135,173,179,140,112,129,205,168,132,194,4,191,175,239,50,66,245,160,26,193,195,232,40,106,60,72,133,32,204,205,104,90,20,60,166,16,214,184,115,44,216,62,82,30,141,124,160,72,173,62,160,67,5,174,33,105,28,248,245,48,15,129,153,96,27,97,125,29,194,233,139,228,8,243,221,79,2,151,52,75,30,47,136,160,103,94,192,58,117,224,88,80,21,183,254,178,135,21,78,20,233,250,7,22,243,14,41,56,12,118,206,224,75,42,96,77,160,225,64,237,254,248,145,134,195,166,49,205,129,233,54,142,136,235,242,10,14,175,76,73,131,26,135,102,237,64,23,102,213,160,167,104,45,101,228,93,89,216,167,142,125,0,216,77,167,4,245,156,140,98,117,19,165,25,185,204,84,161,175,153,193,20,160,53,22,192,197,176,225,102,6,251,115,216,238,53,110,254,106,193,134,232,100,173,93,211,71,195,10,192,107,97,190,165,12,160,104,206,244,51,77,131,79,209,64,233,97,35,142,75,42,205,198,120,222,90,199,168,126,235,12,225,30,240,214,56,253,168,160,230,94,127,56,22,169,3,159,236,49,217,88,2,175,168,22,104,177,154,127,106,165,176,238,236,141,83,64,123,28,177,206,160,140,137,2,195,227,9,182,245,76,62,215,174,168,254,15,125,111,241,30,50,110,189,66,58,230,2,252,104,182,247,223,94,128],[249,2,48,32,185,2,44,249,2,41,1,131,2,246,200,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - res.assert_success(); + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); - assert_proof_was_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_used(&contract, proof_str).await; let deposited_amount = 2000; - - let balance = get_eth_balance( - &master_account, - validate_eth_address(RECIPIENT_ETH_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(RECIPIENT_ETH_ADDRESS)).await; assert_eq!(balance, deposited_amount); - let balance = get_eth_balance( - &master_account, - validate_eth_address(CUSTODIAN_ADDRESS), - CONTRACT_ACC, - ); + let balance = get_eth_balance(&contract, address_from_hex(CUSTODIAN_ADDRESS)).await; assert_eq!(balance, 0); - let balance = total_supply(&master_account, CONTRACT_ACC); + let balance = total_supply(&contract).await; assert_eq!(balance, deposited_amount); - let balance = total_eth_supply_on_aurora(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_aurora(&contract).await; assert_eq!(balance, deposited_amount); - let balance = total_eth_supply_on_near(&master_account, CONTRACT_ACC); + let balance = total_eth_supply_on_near(&contract).await; assert_eq!(balance, deposited_amount); } -#[test] -fn test_deposit_to_near_amount_less_fee() { +#[tokio::test] +async fn test_deposit_to_near_amount_less_fee() { let custodian_address = "73c8931CA2aD746d97a59A7ABDDa0a9205F7ffF9"; - let (master_account, contract) = init(custodian_address); + let contract = init(custodian_address).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,139,92,51,142,163,95,21,160,61,29,148,206,54,147,187,96,77,109,244,8,130,155,249,198,206,30,173,216,144,176,252,123,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,218,9,209,192,173,39,133,109,141,57,2,146,184,12,94,217,6,138,173,67,121,185,24,179,133,189,219,40,81,210,73,106,160,219,108,244,199,44,203,84,71,126,74,82,240,203,255,238,20,226,29,239,51,7,19,144,34,156,137,232,159,71,30,164,29,160,209,61,241,33,17,103,192,203,57,156,112,250,18,166,26,237,248,153,226,185,87,220,156,93,249,17,39,190,125,96,247,239,185,1,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,128,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,32,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,32,0,0,0,0,8,0,0,2,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,0,0,0,0,0,0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,144,4,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,132,91,80,110,139,131,157,118,104,131,122,18,0,131,30,4,87,132,96,175,154,220,140,115,112,105,100,101,114,49,48,1,2,9,64,160,80,163,212,151,183,11,70,219,178,190,167,172,64,187,47,14,29,226,253,132,116,145,81,143,54,249,121,123,193,241,120,249,136,244,120,239,134,243,43,177,139],"proof":[[248,81,160,164,35,68,182,184,52,174,73,6,81,4,92,187,190,187,106,255,124,123,24,244,168,161,247,60,181,75,29,192,175,96,140,128,128,128,128,128,128,128,160,169,157,199,164,106,205,109,88,111,183,255,180,108,15,155,137,126,163,108,44,117,125,138,221,3,188,93,85,146,129,19,139,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promise = &res.promise_results()[res.promise_results().len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, - "Expected failure as the deposited amount is less than fee, but deposit to NEP-141 succeeded", + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).transact().await.err().unwrap(); + + assert_error_message( + &res, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", ); - assert_proof_was_not_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_not_used(&contract, proof_str).await; } -#[test] -fn test_deposit_to_aurora_amount_less_fee() { +#[tokio::test] +async fn test_deposit_to_aurora_amount_less_fee() { let custodian_address = "73c8931CA2aD746d97a59A7ABDDa0a9205F7ffF9"; - let (master_account, contract) = init(custodian_address); + let contract = init(custodian_address).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,132,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,40,1,130,121,119,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,132,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,10,160,234,97,221,132,104,51,119,219,129,206,197,27,130,197,14,113,167,32,152,214,207,205,156,210,35,213,198,227,116,42,51,224,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,15,150,233,184,181,140,226,81,205,139,229,87,226,149,49,207,117,33,36,83,124,8,75,199,231,48,13,23,189,217,179,12,160,241,37,169,74,233,62,231,112,0,207,95,228,68,240,108,254,57,199,255,130,142,158,161,180,243,50,255,222,77,251,252,126,160,31,111,236,60,142,91,35,119,195,92,158,134,65,138,8,247,98,122,229,21,226,85,38,130,141,139,168,60,83,90,63,244,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,128,0,0,0,0,128,0,0,0,32,0,0,0,0,0,0,64,0,0,10,0,0,0,0,0,0,1,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,8,0,0,2,0,0,0,4,0,2,0,0,0,0,0,0,0,0,0,0,0,4,0,0,8,2,0,0,0,0,0,0,136,0,4,40,0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,0,0,32,0,0,10,0,0,0,0,0,0,10,0,1,0,0,0,0,0,0,32,0,0,128,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,16,0,0,64,0,34,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,128,2,0,0,0,128,0,1,32,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,4,0,0,0,32,128,0,0,0,0,0,16,0,0,0,0,0,0,0,0,128,0,0,0,0,128,0,0,0,0,0,0,0,16,0,1,0,16,132,91,127,63,197,131,157,118,142,131,122,18,0,131,25,25,181,132,96,175,156,157,140,115,112,105,100,101,114,49,48,1,2,9,64,160,68,227,115,157,18,184,21,217,93,74,196,34,230,228,210,239,61,26,221,245,191,46,44,135,134,2,20,53,95,18,128,54,136,162,198,27,59,153,146,63,16],"proof":[[248,113,160,204,110,241,220,150,206,51,121,104,130,125,127,249,35,9,242,107,45,164,62,147,221,93,116,73,79,49,96,226,92,235,247,160,43,215,154,177,148,177,15,202,141,217,45,114,108,33,74,0,144,126,189,26,78,152,232,105,119,103,203,51,79,45,113,124,128,128,128,128,128,128,160,74,177,164,103,85,250,153,17,105,68,205,207,176,48,89,230,100,35,20,167,34,117,11,115,14,107,128,214,48,17,53,209,128,128,128,128,128,128,128,128],[249,2,47,48,185,2,43,249,2,40,1,130,121,119,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,132,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promise = &res.promise_results()[res.promise_results().len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, - "Expected failure as the deposited amount is less than fee, but deposit to Aurora succeeded", + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).transact().await.err().unwrap(); + + assert_error_message( + &res, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", ); - assert_proof_was_not_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_not_used(&contract, proof_str).await; } -#[test] -fn test_deposit_to_near_amount_zero_fee_non_zero() { +#[tokio::test] +async fn test_deposit_to_near_amount_zero_fee_non_zero() { let custodian_address = "73c8931CA2aD746d97a59A7ABDDa0a9205F7ffF9"; - let (master_account, contract) = init(custodian_address); + let contract = init(custodian_address).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,244,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,244,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,47,76,8,45,83,192,115,218,108,188,181,117,148,40,254,44,169,118,92,188,207,7,122,246,133,75,100,184,134,128,91,12,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,225,211,110,129,173,98,101,150,55,116,11,30,26,161,226,8,234,249,90,46,245,112,225,68,76,26,215,135,27,181,140,22,160,229,44,239,5,102,141,42,118,174,163,144,225,90,152,120,60,150,25,144,217,154,234,25,69,35,226,103,149,188,127,81,106,160,177,89,93,76,113,24,117,182,174,52,148,6,239,129,151,18,222,56,245,9,232,80,7,129,118,118,108,72,76,247,238,101,185,1,0,1,4,200,10,0,0,0,0,8,0,32,0,128,3,1,0,0,145,4,33,72,8,0,2,0,128,0,18,64,26,38,0,4,16,8,1,136,65,40,32,0,0,1,72,0,2,0,128,0,64,0,0,48,0,32,0,0,0,0,192,0,100,9,0,12,0,16,0,0,1,2,8,8,0,8,12,128,64,0,192,2,0,0,64,2,68,129,0,128,1,0,0,128,128,68,0,64,64,32,0,67,0,32,0,0,41,20,1,0,16,40,0,16,16,32,0,0,0,128,0,0,0,64,48,4,8,8,0,0,0,0,66,32,64,0,0,48,0,16,8,1,64,0,0,16,32,0,33,32,0,0,128,0,2,2,128,0,0,192,0,2,40,0,0,0,0,0,1,0,67,1,0,131,32,6,8,0,0,8,96,128,0,0,0,0,12,0,0,0,65,2,160,2,64,0,2,4,32,0,128,0,1,34,0,105,0,160,0,32,18,32,16,1,0,0,0,20,0,32,0,20,0,96,128,0,16,0,0,64,16,2,192,1,0,4,32,0,32,130,2,0,0,32,0,0,0,4,64,12,64,0,0,4,0,0,1,132,93,96,3,163,131,157,117,205,131,122,18,0,131,113,87,104,132,96,175,145,182,140,115,112,105,100,101,114,49,48,1,2,9,64,160,179,183,88,73,3,20,234,255,8,238,6,186,173,204,149,149,235,233,232,35,158,194,53,246,218,39,221,246,90,7,34,255,136,176,36,100,161,146,27,98,29],"proof":[[248,177,160,93,101,188,48,5,53,36,126,41,0,92,130,188,117,104,230,178,29,27,194,22,86,212,235,193,20,241,42,157,88,117,205,160,141,83,180,197,22,126,217,34,74,50,114,118,42,157,161,171,8,158,98,92,183,124,137,130,211,1,106,44,222,37,13,32,160,62,131,146,138,69,63,89,98,140,64,187,93,207,160,0,4,134,154,205,47,168,231,136,249,129,230,137,29,3,210,67,173,160,76,91,176,245,81,3,198,111,175,230,185,70,220,111,189,88,15,154,173,107,239,121,185,13,159,197,61,37,231,252,22,200,128,128,128,128,160,13,246,139,212,38,202,103,201,31,80,247,136,186,58,17,52,66,119,115,128,23,123,59,166,177,68,79,182,9,242,60,106,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,244,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promise = &res.promise_results()[res.promise_results().len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, - "Expected failure as the deposited amount is zero and the fee is not zero, but deposit to NEP-141 succeeded", + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).transact().await.err().unwrap(); + + assert_error_message( + &res, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", ); - assert_proof_was_not_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_not_used(&contract, proof_str).await; } -#[test] -fn test_deposit_to_aurora_amount_zero_fee_non_zero() { +#[tokio::test] +async fn test_deposit_to_aurora_amount_zero_fee_non_zero() { let custodian_address = "73c8931CA2aD746d97a59A7ABDDa0a9205F7ffF9"; - let (master_account, contract) = init(custodian_address); + let contract = init(custodian_address).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":1,"receipt_data":[249,2,41,1,131,1,110,54,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,21,160,60,128,9,36,168,69,207,249,164,88,177,15,74,221,137,160,110,246,3,133,209,132,169,179,31,86,142,216,160,11,162,137,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,28,255,226,5,233,121,118,187,157,30,192,6,245,34,35,96,168,147,83,224,160,182,206,231,252,255,115,166,11,152,156,84,169,204,36,0,94,3,17,113,103,104,252,225,161,115,85,74,227,104,249,187,232,160,211,106,68,136,2,141,5,14,201,111,68,218,251,84,103,176,66,10,190,123,58,119,216,141,192,197,222,181,211,87,117,192,160,162,200,112,106,166,13,220,187,223,164,251,102,104,106,40,84,17,101,93,131,125,204,193,62,96,110,167,214,54,41,154,191,185,1,0,0,40,72,0,32,0,0,0,0,0,0,5,128,2,0,8,0,128,144,136,0,34,0,0,32,1,0,0,64,16,0,10,0,16,8,28,0,17,9,0,0,0,0,72,0,16,4,0,0,0,0,128,2,18,0,0,0,0,1,16,0,36,0,1,1,32,8,0,2,1,0,64,64,0,0,8,0,16,0,40,2,0,13,0,2,8,0,0,0,8,0,0,16,0,4,16,36,0,52,8,130,128,8,0,0,0,0,10,0,2,40,64,0,34,32,2,0,2,0,0,0,0,0,48,4,32,128,0,32,0,0,2,96,0,0,0,0,64,10,0,33,64,0,0,0,66,0,32,0,0,192,138,0,0,0,70,0,129,128,0,66,32,0,0,16,64,0,0,0,0,97,0,34,0,6,0,0,32,8,0,1,200,128,48,0,41,128,0,128,0,224,0,0,0,0,2,0,64,0,148,0,0,32,72,8,0,96,0,36,128,25,48,33,0,128,16,0,0,4,2,128,4,32,144,0,20,0,0,0,16,2,0,4,0,2,8,0,0,128,0,16,0,0,128,0,0,16,0,128,0,72,16,0,129,0,80,132,91,116,53,37,131,157,118,157,131,122,18,0,131,48,97,222,132,96,175,157,102,151,214,131,1,10,2,132,103,101,116,104,134,103,111,49,46,49,54,133,108,105,110,117,120,160,218,71,54,233,233,153,85,103,64,10,4,159,150,224,130,134,111,78,188,224,102,166,96,148,216,222,134,254,219,185,88,110,136,87,173,68,252,252,248,190,64],"proof":[[248,177,160,174,171,108,131,83,47,244,139,23,122,146,226,84,189,175,114,176,131,196,80,85,155,220,172,151,31,138,121,78,34,1,37,160,104,209,167,107,221,53,22,163,251,61,251,80,40,239,108,253,251,47,253,90,163,103,58,194,173,111,232,90,174,223,154,156,160,185,232,110,109,245,242,193,69,113,230,64,155,37,7,166,98,0,174,149,27,3,242,254,162,87,27,39,206,191,90,97,39,160,156,171,231,120,50,202,239,195,248,47,226,150,143,78,94,254,151,195,12,90,54,253,126,104,200,94,222,173,155,24,75,214,128,128,128,128,160,77,84,120,31,175,114,100,6,171,254,190,44,236,141,143,126,33,139,92,41,101,166,10,135,52,237,241,45,228,121,210,252,128,128,128,128,128,128,128,128],[249,1,241,128,160,112,174,178,81,116,140,64,238,179,40,62,38,72,120,77,248,199,242,3,227,104,227,174,247,54,169,115,176,134,87,216,196,160,208,65,39,69,237,92,207,141,20,26,113,245,146,250,71,165,184,6,221,105,202,34,201,192,206,144,30,169,82,146,191,130,160,250,127,168,75,47,196,128,16,232,187,94,131,103,164,17,74,154,178,32,193,229,188,234,15,63,149,127,95,2,85,36,38,160,9,173,49,32,69,145,114,254,67,59,110,57,126,204,241,26,85,145,117,55,165,249,149,252,11,213,14,224,142,203,167,165,160,49,16,36,243,207,150,120,119,173,146,213,84,201,84,33,132,103,245,138,209,190,215,89,31,100,50,79,241,11,27,117,232,160,38,102,178,111,249,250,245,239,103,241,97,55,179,25,194,214,51,83,145,244,160,76,255,88,140,94,66,211,135,147,231,233,160,86,244,54,180,248,80,19,60,89,82,142,50,237,41,148,80,99,93,184,17,160,129,174,200,175,79,56,156,152,116,246,19,160,141,144,121,114,242,95,79,178,182,13,237,0,226,45,215,70,186,238,115,124,4,185,167,106,170,121,37,27,22,90,85,154,160,38,169,214,240,80,51,77,173,121,227,163,72,68,190,21,194,23,235,129,2,183,83,211,21,67,152,206,246,236,168,183,65,160,220,198,172,57,188,229,136,230,231,56,249,171,3,156,137,119,188,173,183,120,220,15,214,253,121,102,45,164,53,244,173,237,160,222,126,139,114,159,32,8,38,110,8,161,127,50,42,173,124,148,83,169,13,252,160,28,62,186,159,153,201,217,244,7,198,160,29,57,238,34,65,21,193,24,140,71,159,181,152,57,184,3,168,102,8,32,23,158,117,205,137,200,143,228,205,234,96,193,160,58,189,88,46,177,57,9,115,13,24,65,37,199,71,182,207,65,18,246,93,175,169,131,142,153,178,213,138,143,236,72,168,160,182,214,186,170,95,22,45,113,224,141,88,205,33,22,49,65,219,4,25,205,180,125,40,18,42,158,62,30,25,244,226,104,160,123,14,60,111,154,53,84,127,228,3,253,5,6,81,188,37,133,89,45,219,175,223,9,211,254,199,3,74,27,75,37,136,128],[249,2,48,32,185,2,44,249,2,41,1,131,1,110,54,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promise = &res.promise_results()[res.promise_results().len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, - "Expected failure as the deposited amount is zero and the fee is not zero, but deposit to Aurora succeeded", + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).transact().await.err().unwrap(); + + assert_error_message( + &res, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", ); - assert_proof_was_not_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_not_used(&contract, proof_str).await; } -#[test] -fn test_deposit_to_near_amount_equal_fee_non_zero() { +#[tokio::test] +async fn test_deposit_to_near_amount_equal_fee_non_zero() { let custodian_address = "73c8931CA2aD746d97a59A7ABDDa0a9205F7ffF9"; - let (master_account, contract) = init(custodian_address); + let contract = init(custodian_address).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,218,232,90,75,133,17,151,21,23,64,121,155,74,131,239,243,28,65,81,101,213,156,148,217,134,34,235,41,62,11,232,147,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,25,127,76,71,206,220,252,85,22,156,38,36,158,35,56,3,255,85,230,138,132,44,102,196,217,205,43,20,129,6,50,114,160,217,211,225,144,113,34,139,65,28,148,21,243,90,204,109,152,98,172,147,56,158,109,65,77,74,110,116,227,7,143,157,97,160,35,108,188,133,254,137,74,53,234,147,11,115,83,161,215,174,6,192,214,61,8,113,178,151,91,57,163,102,121,177,113,30,185,1,0,144,48,72,0,8,0,0,0,48,0,0,1,128,128,128,0,128,128,0,8,64,2,1,0,5,1,0,32,64,16,129,8,0,16,8,8,128,1,9,8,4,0,0,104,0,0,0,24,8,0,4,0,8,0,0,0,0,128,64,32,16,32,0,0,92,2,8,0,10,1,80,24,1,0,0,8,17,1,0,40,0,0,5,0,130,17,0,0,6,0,0,1,128,0,2,16,40,0,96,16,2,2,0,0,0,0,32,8,0,64,40,65,0,0,32,0,0,8,0,0,2,0,0,112,0,0,0,4,8,0,64,2,0,0,5,0,161,212,88,1,5,0,0,32,8,0,2,32,0,0,2,136,0,0,4,66,34,0,128,0,2,8,128,0,0,0,0,128,44,8,0,0,19,20,2,8,2,0,8,128,132,0,0,0,0,56,0,0,0,4,33,32,32,129,0,2,0,0,128,145,64,0,96,112,136,2,32,0,32,16,0,0,65,0,84,16,64,2,0,16,161,0,34,128,128,16,0,0,8,16,2,12,2,0,0,18,64,4,128,0,152,0,44,0,8,0,0,0,64,0,32,148,0,16,128,0,132,91,126,153,161,131,157,118,120,131,122,18,0,131,55,185,255,132,96,175,155,143,140,115,112,105,100,101,114,49,48,1,2,9,64,160,29,62,139,98,163,60,78,159,159,190,165,213,126,42,39,157,104,12,168,1,9,24,24,157,45,96,113,188,166,18,114,253,136,161,226,143,133,82,9,96,55],"proof":[[248,145,160,153,98,12,82,79,154,121,176,11,226,192,161,140,213,198,195,143,185,79,36,156,98,17,141,146,111,76,206,149,161,186,244,160,29,41,24,128,95,59,50,57,188,69,166,227,81,94,29,115,178,144,71,219,248,16,233,179,158,64,222,175,67,156,221,186,160,221,78,89,28,71,2,204,57,50,75,194,224,88,108,127,122,110,247,48,111,72,110,252,199,127,138,177,160,1,244,75,250,128,128,128,128,128,160,96,141,238,91,85,76,114,97,220,74,251,25,18,72,46,126,72,190,245,222,173,235,62,157,59,131,133,200,217,240,218,101,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promise = &res.promise_results()[res.promise_results().len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, - "Expected failure as the deposited amount is equal to fee, but deposit to NEP-141 succeeded", + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).transact().await.err().unwrap(); + + assert_error_message( + &res, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", ); - assert_proof_was_not_used(&contract, CONTRACT_ACC, proof_str); + assert_proof_was_not_used(&contract, proof_str).await; } -#[test] -fn test_deposit_to_aurora_amount_equal_fee_non_zero() { +#[tokio::test] +async fn test_deposit_to_aurora_amount_equal_fee_non_zero() { let custodian_address = "73c8931CA2aD746d97a59A7ABDDa0a9205F7ffF9"; - let (master_account, contract) = init(custodian_address); + let contract = init(custodian_address).await.unwrap(); let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,40,1,130,121,119,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,10,160,40,73,143,87,82,108,249,199,149,251,138,16,158,32,40,191,70,185,139,157,146,47,76,134,132,2,138,15,163,195,164,23,160,4,220,65,246,216,41,193,152,14,191,243,6,120,77,198,249,10,186,90,192,38,182,89,163,180,7,115,149,220,146,135,121,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,140,129,164,138,92,240,141,148,58,223,100,113,117,102,163,205,129,110,47,12,254,66,40,98,179,170,247,163,117,111,198,112,160,154,8,216,215,130,120,77,117,89,130,236,187,91,119,167,212,252,114,44,157,54,25,178,246,190,125,110,255,187,224,200,236,160,40,108,11,169,34,110,94,30,9,115,148,248,253,252,64,245,150,237,108,188,197,225,88,28,139,188,249,78,249,118,101,180,185,1,0,128,32,72,128,0,0,0,0,0,0,32,1,128,2,32,0,2,130,0,0,2,51,0,0,0,1,0,0,66,16,0,10,0,144,8,12,0,1,13,32,0,0,0,72,0,0,0,0,0,64,0,0,32,2,0,0,2,0,0,0,0,32,0,0,0,0,40,0,34,1,0,0,8,0,0,8,0,0,0,46,0,2,5,0,2,0,0,8,64,1,32,0,0,0,0,16,36,96,32,8,66,2,0,128,0,1,0,8,0,2,40,64,4,0,40,2,0,2,13,32,0,0,192,176,4,76,128,4,32,128,0,10,0,0,0,0,4,64,42,136,1,0,0,0,0,0,4,160,1,0,128,136,4,0,0,66,0,1,129,0,2,0,0,16,0,0,0,0,0,0,64,0,50,64,2,0,0,0,8,0,1,8,1,160,0,42,128,0,128,16,160,0,192,0,0,2,0,96,16,144,0,32,48,64,8,128,32,0,164,16,0,32,1,1,0,16,0,0,5,2,192,0,32,128,2,16,0,8,0,18,2,0,0,16,0,0,0,0,128,0,80,0,0,128,0,32,0,0,0,0,0,16,0,1,0,16,132,91,150,244,27,131,157,118,173,131,122,18,0,131,40,221,54,132,96,175,158,25,140,115,112,105,100,101,114,49,48,1,2,9,64,160,218,157,103,144,72,1,176,23,70,255,185,190,128,163,131,210,184,249,29,138,99,94,110,182,239,251,248,20,139,58,221,102,136,127,48,25,31,42,252,69,90],"proof":[[248,145,160,242,107,136,177,199,137,149,29,37,76,252,130,24,241,231,253,164,161,49,123,187,119,248,194,41,74,148,86,89,189,140,122,160,221,253,158,175,54,102,36,195,73,91,187,167,57,197,110,107,81,39,3,67,139,234,202,103,171,85,168,245,23,151,146,101,160,240,166,241,60,58,19,14,113,70,156,230,223,214,171,111,192,135,200,157,176,100,11,127,9,6,211,142,63,158,86,97,87,128,128,128,128,128,160,247,26,205,35,167,94,67,103,248,63,247,181,235,154,151,144,26,0,253,18,81,231,65,62,46,101,62,205,117,218,221,122,128,128,128,128,128,128,128,128],[249,2,47,48,185,2,43,249,2,40,1,130,121,119,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,188,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; - let proof: Proof = serde_json::from_str(proof_str).unwrap(); - - let res = master_account.call( - CONTRACT_ACC.parse().unwrap(), - "deposit", - &proof.try_to_vec().unwrap(), - DEFAULT_GAS, - 0, - ); - let promise = &res.promise_results()[res.promise_results().len() - 2]; - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - ERR_NOT_ENOUGH_BALANCE_FOR_FEE, - "Expected failure as the deposited amount is equal to fee, but deposit to Aurora succeeded", - ); + let proof = serde_json::from_str(proof_str).unwrap(); + let res = contract.deposit(proof).transact().await.err().unwrap(); - assert_proof_was_not_used(&contract, CONTRACT_ACC, proof_str); -} + assert_error_message( + &res, + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE_FOR_FEE", + ); -fn assert_execution_status_failure( - execution_status: ExecutionStatus, - err_msg: &str, - panic_msg: &str, -) { - // Usually the converted to string has either of following two messages formats: - // "Action #0: Smart contract panicked: ERR_MSG [src/some_file.rs:LINE_NUMBER:COLUMN_NUMBER]" - // "right: 'MISMATCHED_DATA': ERR_MSG [src/some_file.rs:LINE_NUMBER:COLUMN_NUMBER]" - // So the ": ERR_MSG [" pattern should catch all invariants of error, even if one of the errors - // message is a subset of another one (e.g. `ERR_MSG_FAILED` is a subset of `ERR_MSG_FAILED_FOO`) - let expected_err_msg_pattern = format!(": {err_msg}"); - - match execution_status { - ExecutionStatus::Failure(err) => { - println!("Error: {err}"); - assert!(err.to_string().contains(&expected_err_msg_pattern)); - } - _ => panic!("{panic_msg}"), - } + assert_proof_was_not_used(&contract, proof_str).await; } -#[test] -fn test_ft_transfer_max_value() { - let (_, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_ft_transfer_max_value() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); - let transfer_amount = u128::MAX; - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer", - json!({ + let res = contract + .root() + .call(&contract.id(), "ft_transfer") + .args_json(json!({ "receiver_id": DEPOSITED_RECIPIENT, - "amount": transfer_amount.to_string(), + "amount": u128::MAX.to_string(), "memo": "transfer memo" - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - let promises = res.promise_results(); - let promise = &promises[promises.len() - 3]; - eprintln!("{:#?}", promise.as_ref().unwrap().outcome().clone().status); - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - "ERR_NOT_ENOUGH_BALANCE", - "Expected failure as the amount is too large", + })) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_failure()); + assert_error_message( + &res.into_result().err().unwrap(), + "Smart contract panicked: ERR_NOT_ENOUGH_BALANCE", ); } -#[test] -fn test_ft_transfer_empty_value() { - let (_, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_ft_transfer_empty_value() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let result = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(result.is_success()); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer", - json!({ + let res = contract + .root() + .call(&contract.id(), "ft_transfer") + .args_json(json!({ "receiver_id": DEPOSITED_RECIPIENT, "amount": "", "memo": "transfer memo" - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - let promises = res.promise_results(); - let promise = &promises[promises.len() - 3]; - eprintln!("{:#?}", promise.as_ref().unwrap().outcome().clone().status); - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - "cannot parse integer from empty string", - "Expected failure as empty string can't be parsed to u128", + })) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_failure()); + assert_error_message( + &res.into_result().err().unwrap(), + "Smart contract panicked: cannot parse integer from empty string", ); } -#[test] -fn test_ft_transfer_wrong_u128_json_type() { - let (_, contract) = init(CUSTODIAN_ADDRESS); - call_deposit_eth_to_near(&contract, CONTRACT_ACC); +#[tokio::test] +async fn test_ft_transfer_wrong_u128_json_type() { + let contract = init(CUSTODIAN_ADDRESS).await.unwrap(); + let res = call_deposit_eth_to_near(&contract).await.unwrap(); + assert!(res.is_success()); - let res = contract.call( - CONTRACT_ACC.parse().unwrap(), - "ft_transfer", - json!({ + let res = contract + .root() + .call(&contract.id().as_ref().parse().unwrap(), "ft_transfer") + .args_json(json!({ "receiver_id": DEPOSITED_RECIPIENT, "amount": 200, "memo": "transfer memo" - }) - .to_string() - .as_bytes(), - DEFAULT_GAS, - 1, - ); - let promises = res.promise_results(); - let promise = &promises[promises.len() - 3]; - eprintln!("{:#?}", promise.as_ref().unwrap().outcome().clone().status); - assert_execution_status_failure( - promise.as_ref().unwrap().outcome().clone().status, - "Wait for a string but got: 200", - "Expected failure as number type can't be parsed to u128", + })) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(res.is_failure()); + assert_error_message( + &res.into_result().err().unwrap(), + "Smart contract panicked: Wait for a string but got: 200 at line 1 column 13", ); } @@ -1674,6 +1121,143 @@ fn dummy_ft_receiver_bytes() -> Vec { .join("tests") .join("ft-receiver"); let output_path = base_path.join("target/wasm32-unknown-unknown/release/ft_receiver.wasm"); - crate::test_utils::rust::compile(base_path); + crate::utils::rust::compile(base_path); std::fs::read(output_path).unwrap() } + +async fn init(custodian_address: &str) -> anyhow::Result { + EngineContractBuilder::new()? + .with_code(crate::utils::AuroraRunner::default().code.code().to_vec()) + .with_owner_id(CONTRACT_ACC)? + .with_prover_id(PROVER_ACCOUNT)? + .with_custodian_address(custodian_address)? + .deploy_and_init() + .await +} + +async fn call_deposit_eth_to_near(contract: &EngineContract) -> anyhow::Result { + let proof = serde_json::from_str(PROOF_DATA_NEAR).unwrap(); + let res = contract.deposit(proof).max_gas().transact().await?; + Ok(res.outcome().clone()) +} + +async fn call_is_used_proof(contract: &EngineContract, proof: &str) -> bool { + let proof = serde_json::from_str(proof).unwrap(); + contract.is_used_proof(proof).await.unwrap().result +} + +async fn assert_proof_was_used(contract: &EngineContract, proof: &str) { + let is_used_proof = call_is_used_proof(contract, proof).await; + assert!( + is_used_proof, + "{}", + "Expected not to fail because the proof should have been already used", + ); +} + +async fn assert_proof_was_not_used(contract: &EngineContract, proof: &str) { + let is_used_proof = call_is_used_proof(contract, proof).await; + assert!( + !is_used_proof, + "{}", + "Expected not to fail and to have an unused proof but it was already used", + ); +} + +async fn call_deposit_eth_to_aurora(contract: &EngineContract) { + let proof = serde_json::from_str(PROOF_DATA_ETH).unwrap(); + let res = contract.deposit(proof).max_gas().transact().await.unwrap(); + assert!(res.is_success()); +} + +async fn get_eth_on_near_balance(contract: &EngineContract, account: &str) -> u128 { + contract + .ft_balance_of(&account.parse().unwrap()) + .await + .unwrap() + .result + .0 +} + +async fn get_eth_balance(contract: &EngineContract, address: Address) -> u128 { + contract.ft_balance_of_eth(address).await.unwrap().result.0 +} + +async fn total_supply(contract: &EngineContract) -> u128 { + contract.ft_total_supply().await.unwrap().result.0 +} + +async fn total_eth_supply_on_near(contract: &EngineContract) -> u128 { + contract + .ft_total_eth_supply_on_near() + .await + .unwrap() + .result + .0 +} + +async fn total_eth_supply_on_aurora(contract: &EngineContract) -> u128 { + contract + .ft_total_eth_supply_on_aurora() + .await + .unwrap() + .result + .0 +} + +fn assert_error_message(err: &T, expected: &str) { + let err_msg = format!("{err:?}"); + assert!(err_msg.contains(expected)); +} + +fn generate_dummy_proof(message: &str, deposit_amount: u128, log_index: u64) -> Proof { + use aurora_engine::deposit_event::TokenMessageData; + + let eth_custodian_address = address_from_hex(CUSTODIAN_ADDRESS); + let fee: Fee = 0.into(); + let token_message_data = + TokenMessageData::parse_event_message_and_prepare_token_message_data(message, fee).unwrap(); + + let deposit_event = aurora_engine::deposit_event::DepositedEvent { + eth_custodian_address, + sender: Address::zero(), + token_message_data, + amount: NEP141Wei::new(deposit_amount), + fee, + }; + + let event_schema = ethabi::Event { + name: aurora_engine::deposit_event::DEPOSITED_EVENT.into(), + inputs: aurora_engine::deposit_event::DepositedEvent::event_params(), + anonymous: false, + }; + let log_entry = aurora_engine_types::parameters::connector::LogEntry { + address: eth_custodian_address.raw(), + topics: vec![ + event_schema.signature(), + // the sender is not important + H256::zero(), + ], + data: ethabi::encode(&[ + ethabi::Token::String(message.to_string()), + ethabi::Token::Uint(U256::from(deposit_event.amount.as_u128())), + ethabi::Token::Uint(U256::from(deposit_event.fee.as_u128())), + ]), + }; + + Proof { + log_index, + // Only this field matters for the purpose of this test + log_entry_data: rlp::encode(&log_entry).to_vec(), + receipt_index: 1, + ..Default::default() + } +} + +fn create_message(account_id: &str, address: &str, fee: u128) -> String { + let mut buffer = [0; 32]; + U256::from(fee).to_little_endian(&mut buffer); + let msg = [&buffer, address_from_hex(address).as_bytes()].concat(); + + [account_id, hex::encode(msg).as_str()].join(":") +} diff --git a/engine-tests/src/tests/ghsa_3p69_m8gg_fwmf.rs b/engine-tests/src/tests/ghsa_3p69_m8gg_fwmf.rs index fe730edb9..7e8dce9de 100644 --- a/engine-tests/src/tests/ghsa_3p69_m8gg_fwmf.rs +++ b/engine-tests/src/tests/ghsa_3p69_m8gg_fwmf.rs @@ -1,11 +1,11 @@ -use crate::test_utils; -use borsh::BorshSerialize; +use crate::utils; +use aurora_engine_types::borsh::BorshSerialize; #[test] fn test_exploit_fix() { let (mut runner, mut signer, _) = crate::tests::sanity::initialize_transfer(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "echo.sol", @@ -38,8 +38,8 @@ fn test_exploit_fix() { .unwrap(); let tx = contract.call_method_with_args("echo", &[ethabi::Token::Bytes(payload)], nonce.into()); - let sender = test_utils::address_from_secret_key(&signer.secret_key); - let view_call_args = test_utils::as_view_call(tx, sender); + let sender = utils::address_from_secret_key(&signer.secret_key); + let view_call_args = utils::as_view_call(tx, sender); let input = view_call_args.try_to_vec().unwrap(); let error = runner.one_shot().call("view", "viewer", input).unwrap_err(); diff --git a/engine-tests/src/tests/mod.rs b/engine-tests/src/tests/mod.rs index 4b4c4fe06..4f1c3c61d 100644 --- a/engine-tests/src/tests/mod.rs +++ b/engine-tests/src/tests/mod.rs @@ -1,11 +1,9 @@ -mod access_lists; mod account_id_precompiles; mod contract_call; mod ecrecover; -mod eip1559; mod erc20; mod erc20_connector; -pub mod eth_connector; +mod eth_connector; mod ghsa_3p69_m8gg_fwmf; #[cfg(feature = "meta-call")] mod meta_parsing; @@ -23,6 +21,7 @@ mod self_destruct_state; mod serde; mod standalone; mod standard_precompiles; -mod state_migration; +mod transaction; pub mod uniswap; +mod upgrade; pub mod xcc; diff --git a/engine-tests/src/tests/modexp.rs b/engine-tests/src/tests/modexp.rs index 7fcbfe7af..83eae40ac 100644 --- a/engine-tests/src/tests/modexp.rs +++ b/engine-tests/src/tests/modexp.rs @@ -5,7 +5,7 @@ use rand::{Rng, SeedableRng}; use super::sanity::initialize_transfer; use crate::prelude::Wei; use crate::prelude::{make_address, Address, U256}; -use crate::test_utils::{self, standalone::StandaloneRunner, AuroraRunner, Signer}; +use crate::utils::{self, standalone::StandaloneRunner, AuroraRunner, Signer}; const MODEXP_ADDRESS: Address = make_address(0, 5); @@ -95,14 +95,14 @@ fn bench_modexp_standalone() { let deploy_contract = |standalone: &mut StandaloneRunner, signer: &mut Signer, path| { let contract_code = std::fs::read_to_string(path).unwrap(); - let deploy_tx = test_utils::create_deploy_transaction( + let deploy_tx = utils::create_deploy_transaction( hex::decode(contract_code.trim()).unwrap(), signer.use_nonce().into(), ); let deploy_result = standalone .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); - Address::try_from_slice(&test_utils::unwrap_success(deploy_result)).unwrap() + Address::try_from_slice(&utils::unwrap_success(deploy_result)).unwrap() }; let do_bench = |standalone: &mut StandaloneRunner, signer: &mut Signer, path| { @@ -187,10 +187,7 @@ fn check_wasm_modexp( } }) .unwrap(); - assert_eq!( - expected_output, - test_utils::unwrap_success_slice(&wasm_result), - ); + assert_eq!(expected_output, utils::unwrap_success_slice(&wasm_result)); } /// Input to the modexp call (base, exp, modulus in big-endian bytes). @@ -269,7 +266,7 @@ impl BenchResult { } struct ModExpBenchContext { - inner: test_utils::AuroraRunner, + inner: AuroraRunner, } impl ModExpBenchContext { @@ -310,20 +307,18 @@ impl ModExpBenchContext { impl Default for ModExpBenchContext { fn default() -> Self { - let mut inner = test_utils::AuroraRunner::default(); - + let mut inner = AuroraRunner::default(); let bench_contract_bytes = { let base_path = std::path::Path::new("../etc") .join("tests") .join("modexp-bench"); let output_path = base_path.join("target/wasm32-unknown-unknown/release/modexp_bench.wasm"); - test_utils::rust::compile(base_path); + utils::rust::compile(base_path); std::fs::read(output_path).unwrap() }; inner.wasm_config.limit_config.max_gas_burnt = u64::MAX; - inner.code = ContractCode::new(bench_contract_bytes, None); Self { inner } diff --git a/engine-tests/src/tests/multisender.rs b/engine-tests/src/tests/multisender.rs index 1c8f8ed5c..efb143167 100644 --- a/engine-tests/src/tests/multisender.rs +++ b/engine-tests/src/tests/multisender.rs @@ -1,4 +1,5 @@ -use crate::test_utils; +use crate::utils; +use crate::utils::solidity::erc20::ERC20; use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::types::{Address, Wei}; use aurora_engine_types::U256; @@ -12,8 +13,7 @@ fn test_multisender_eth() { let mut multi_send_eth = |num_addr: usize| -> (u64, u64) { let destinations: Vec<(Address, U256)> = (0..num_addr) .map(|_| { - let address = - test_utils::address_from_secret_key(&test_utils::Signer::random().secret_key); + let address = utils::address_from_secret_key(&utils::Signer::random().secret_key); let amount = Wei::from_eth(U256::one()).unwrap().raw(); (address, amount) }) @@ -24,7 +24,7 @@ fn test_multisender_eth() { call_contract(contract_address, nonce, send_eth_data(&destinations)) }) .unwrap(); - test_utils::unwrap_success_slice(&result); + utils::unwrap_success_slice(&result); (result.gas_used, profile.all_gas()) }; @@ -37,37 +37,36 @@ fn test_multisender_eth() { #[test] fn test_multisender_erc20() { let (mut runner, mut signer, contract_address) = initialize(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let erc20 = { - let constructor = test_utils::erc20::ERC20Constructor::load(); + let constructor = utils::solidity::erc20::ERC20Constructor::load(); let nonce = signer.use_nonce(); let contract = runner.deploy_contract( &signer.secret_key, |c| c.deploy("TEST_A", "AAA", nonce.into()), constructor, ); - test_utils::erc20::ERC20(contract) + ERC20(contract) }; let result = runner .submit_with_signer(&mut signer, |nonce| { erc20.mint(signer_address, U256::from(u128::MAX), nonce) }) .unwrap(); - test_utils::unwrap_success_slice(&result); + utils::unwrap_success_slice(&result); let result = runner .submit_with_signer(&mut signer, |nonce| { erc20.approve(contract_address, U256::from(u128::MAX), nonce) }) .unwrap(); - test_utils::unwrap_success_slice(&result); + utils::unwrap_success_slice(&result); let mut multi_send_erc20 = |num_addr: usize| -> (u64, u64) { let destinations: Vec<(Address, U256)> = (0..num_addr) .map(|_| { - let address = - test_utils::address_from_secret_key(&test_utils::Signer::random().secret_key); + let address = utils::address_from_secret_key(&utils::Signer::random().secret_key); let amount = U256::from(1); (address, amount) }) @@ -82,7 +81,7 @@ fn test_multisender_erc20() { ) }) .unwrap(); - test_utils::unwrap_success_slice(&result); + utils::unwrap_success_slice(&result); (result.gas_used, profile.all_gas()) }; @@ -121,16 +120,16 @@ fn send_eth_data(amounts: &[(Address, U256)]) -> Vec { result } -fn initialize() -> (test_utils::AuroraRunner, test_utils::Signer, Address) { - let mut runner = test_utils::deploy_evm(); +fn initialize() -> (utils::AuroraRunner, utils::Signer, Address) { + let mut runner = utils::deploy_runner(); runner.wasm_config.limit_config.max_gas_burnt = u64::MAX; let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); let initial_balance = Wei::new(U256::from(u128::MAX)); runner.create_address(source_address, initial_balance, INITIAL_NONCE.into()); - let mut signer = test_utils::Signer::new(source_account); + let mut signer = utils::Signer::new(source_account); signer.nonce = INITIAL_NONCE; let deploy_code = hex::decode( @@ -141,23 +140,22 @@ fn initialize() -> (test_utils::AuroraRunner, test_utils::Signer, Address) { .unwrap(); let result = runner .submit_with_signer(&mut signer, |nonce| { - let mut tx = test_utils::create_deploy_transaction(Vec::new(), nonce); + let mut tx = utils::create_deploy_transaction(Vec::new(), nonce); tx.data = deploy_code; tx }) .unwrap(); - let contract_address = - Address::try_from_slice(test_utils::unwrap_success_slice(&result)).unwrap(); + let contract_address = Address::try_from_slice(utils::unwrap_success_slice(&result)).unwrap(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let result = runner .submit_with_signer(&mut signer, |nonce| { - let mut tx = test_utils::transfer(contract_address, Wei::zero(), nonce); + let mut tx = utils::transfer(contract_address, Wei::zero(), nonce); tx.data = initialize_data(signer_address); tx }) .unwrap(); - test_utils::unwrap_success(result); + utils::unwrap_success(result); (runner, signer, contract_address) } @@ -175,7 +173,7 @@ fn initialize_data(owner_address: Address) -> Vec { } fn call_contract(contract_address: Address, nonce: U256, data: Vec) -> TransactionLegacy { - let mut tx = test_utils::transfer(contract_address, Wei::zero(), nonce); + let mut tx = utils::transfer(contract_address, Wei::zero(), nonce); tx.data = data; tx } diff --git a/engine-tests/src/tests/one_inch.rs b/engine-tests/src/tests/one_inch.rs index 6ae4a294c..805648635 100644 --- a/engine-tests/src/tests/one_inch.rs +++ b/engine-tests/src/tests/one_inch.rs @@ -1,8 +1,8 @@ use crate::prelude::parameters::SubmitResult; use crate::prelude::{Wei, U256}; -use crate::test_utils::one_inch::liquidity_protocol; -use crate::test_utils::{self, assert_gas_bound}; -use borsh::BorshDeserialize; +use crate::utils::one_inch::liquidity_protocol; +use crate::utils::{self, assert_gas_bound}; +use aurora_engine_types::borsh::BorshDeserialize; use libsecp256k1::SecretKey; use near_vm_logic::VMOutcome; use std::sync::Once; @@ -30,7 +30,7 @@ fn test_1inch_liquidity_protocol() { assert_gas_bound(profile.all_gas(), 9); // less than 9 NEAR Tgas used // create some ERC-20 tokens to have a liquidity pool for - let signer_address = test_utils::address_from_secret_key(&helper.signer.secret_key); + let signer_address = utils::address_from_secret_key(&helper.signer.secret_key); let token_a = helper.create_erc20("TokenA", "AAA"); let token_b = helper.create_erc20("TokenB", "BBB"); helper.mint_erc20_tokens(&token_a, signer_address); @@ -93,7 +93,7 @@ fn test_1_inch_limit_order_deploy() { let (mut runner, mut source_account) = initialize(); let outcome = deploy_1_inch_limit_order_contract(&mut runner, &mut source_account); - let profile = test_utils::ExecutionProfile::new(&outcome); + let profile = utils::ExecutionProfile::new(&outcome); let result: SubmitResult = SubmitResult::try_from_slice(&outcome.return_data.as_value().unwrap()).unwrap(); assert!(result.status.is_ok()); @@ -111,17 +111,17 @@ fn test_1_inch_limit_order_deploy() { } fn deploy_1_inch_limit_order_contract( - runner: &mut test_utils::AuroraRunner, - signer: &mut test_utils::Signer, + runner: &mut utils::AuroraRunner, + signer: &mut utils::Signer, ) -> VMOutcome { - let artifacts_path = test_utils::one_inch::download_and_compile_solidity_sources( + let artifacts_path = utils::one_inch::download_and_compile_solidity_sources( "limit-order-protocol", &DOWNLOAD_ONCE, &COMPILE_ONCE, ); let contract_path = artifacts_path.join("LimitOrderProtocol.sol/LimitOrderProtocol.json"); let constructor = - test_utils::solidity::ContractConstructor::compile_from_extended_json(contract_path); + utils::solidity::ContractConstructor::compile_from_extended_json(contract_path); let nonce = signer.use_nonce(); let deploy_tx = crate::prelude::transactions::legacy::TransactionLegacy { @@ -132,25 +132,21 @@ fn deploy_1_inch_limit_order_contract( value: Wei::default(), data: constructor.code, }; - let tx = test_utils::sign_transaction(deploy_tx, Some(runner.chain_id), &signer.secret_key); - let outcome = runner.call( - test_utils::SUBMIT, - "any_account.near", - rlp::encode(&tx).to_vec(), - ); + let tx = utils::sign_transaction(deploy_tx, Some(runner.chain_id), &signer.secret_key); + let outcome = runner.call(utils::SUBMIT, "any_account.near", rlp::encode(&tx).to_vec()); assert!(outcome.is_ok()); outcome.unwrap() } -fn initialize() -> (test_utils::AuroraRunner, test_utils::Signer) { +fn initialize() -> (utils::AuroraRunner, utils::Signer) { // set up Aurora runner and accounts - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); runner.create_address(source_address, INITIAL_BALANCE, INITIAL_NONCE.into()); - let mut signer = test_utils::Signer::new(source_account); + let mut signer = utils::Signer::new(source_account); signer.nonce = INITIAL_NONCE; (runner, signer) diff --git a/engine-tests/src/tests/pausable_precompiles.rs b/engine-tests/src/tests/pausable_precompiles.rs index 6ebff130f..7d86820c1 100644 --- a/engine-tests/src/tests/pausable_precompiles.rs +++ b/engine-tests/src/tests/pausable_precompiles.rs @@ -1,19 +1,19 @@ use crate::prelude::{Address, U256}; -use crate::test_utils::exit_precompile::{Tester, TesterConstructor}; -use crate::test_utils::{ +use crate::utils::solidity::exit_precompile::{Tester, TesterConstructor}; +use crate::utils::{ self, AuroraRunner, Signer, ORIGIN, PAUSED_PRECOMPILES, PAUSE_PRECOMPILES, RESUME_PRECOMPILES, }; use aurora_engine::engine::EngineErrorKind; use aurora_engine::parameters::{PausePrecompilesCallArgs, TransactionStatus}; +use aurora_engine_types::borsh::BorshSerialize; use aurora_engine_types::types::Wei; -use borsh::BorshSerialize; const EXIT_TO_ETHEREUM_FLAG: u32 = 0b10; const CALLED_ACCOUNT_ID: &str = "aurora"; #[test] fn test_paused_precompile_is_shown_when_viewing() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let call_args = PausePrecompilesCallArgs { paused_mask: EXIT_TO_ETHEREUM_FLAG, @@ -84,7 +84,7 @@ fn test_executing_paused_and_then_resumed_precompile_succeeds() { #[test] fn test_resuming_precompile_does_not_throw_error() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let call_args = PausePrecompilesCallArgs { paused_mask: 0b1 }; @@ -98,7 +98,7 @@ fn test_resuming_precompile_does_not_throw_error() { #[test] fn test_pausing_precompile_does_not_throw_error() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let call_args = PausePrecompilesCallArgs { paused_mask: 0b1 }; let input = call_args.try_to_vec().unwrap(); let result = runner.call(PAUSE_PRECOMPILES, CALLED_ACCOUNT_ID, input); @@ -109,11 +109,11 @@ fn test_pausing_precompile_does_not_throw_error() { fn setup_test() -> (AuroraRunner, Signer, Address, Tester) { const INITIAL_NONCE: u64 = 0; - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let token = runner.deploy_erc20_token("tt.testnet"); let mut signer = Signer::random(); runner.create_address( - test_utils::address_from_secret_key(&signer.secret_key), + utils::address_from_secret_key(&signer.secret_key), Wei::from_eth(1.into()).unwrap(), INITIAL_NONCE.into(), ); diff --git a/engine-tests/src/tests/pause_contract.rs b/engine-tests/src/tests/pause_contract.rs index b06698b45..5d810f6b2 100644 --- a/engine-tests/src/tests/pause_contract.rs +++ b/engine-tests/src/tests/pause_contract.rs @@ -1,10 +1,10 @@ -use crate::test_utils; +use crate::utils; use aurora_engine::parameters::SetUpgradeDelayBlocksArgs; -use borsh::BorshSerialize; +use aurora_engine_types::borsh::BorshSerialize; #[test] fn test_pause_contract_require_owner() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); let result = runner.call("pause_contract", &aurora_account_id, vec![]); @@ -19,7 +19,7 @@ fn test_pause_contract_require_owner() { #[test] fn test_resume_contract_require_owner() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); let result = runner.call("pause_contract", &aurora_account_id, vec![]); @@ -37,7 +37,7 @@ fn test_resume_contract_require_owner() { #[test] fn test_pause_contract_require_running() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); let result = runner.call("pause_contract", &aurora_account_id, vec![]); @@ -49,7 +49,7 @@ fn test_pause_contract_require_running() { #[test] fn test_resume_contract_require_paused() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); let result = runner.call("resume_contract", &aurora_account_id, vec![]); @@ -64,7 +64,7 @@ fn test_resume_contract_require_paused() { #[test] fn test_pause_contract() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); let set = SetUpgradeDelayBlocksArgs { upgrade_delay_blocks: 2, @@ -93,7 +93,7 @@ fn test_pause_contract() { #[test] fn test_resume_contract() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); let set = SetUpgradeDelayBlocksArgs { upgrade_delay_blocks: 2, diff --git a/engine-tests/src/tests/prepaid_gas_precompile.rs b/engine-tests/src/tests/prepaid_gas_precompile.rs index e360afa08..6330ade9d 100644 --- a/engine-tests/src/tests/prepaid_gas_precompile.rs +++ b/engine-tests/src/tests/prepaid_gas_precompile.rs @@ -1,4 +1,4 @@ -use crate::test_utils::{self, standalone}; +use crate::utils::{self, standalone}; use aurora_engine_precompiles::prepaid_gas; use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::{types::Wei, U256}; @@ -6,8 +6,8 @@ use aurora_engine_types::{types::Wei, U256}; #[test] fn test_prepaid_gas_precompile() { const EXPECTED_VALUE: u64 = 157_277_246_352_223; - let mut signer = test_utils::Signer::random(); - let mut runner = test_utils::deploy_evm(); + let mut signer = utils::Signer::random(); + let mut runner = utils::deploy_runner(); let mut standalone = standalone::StandaloneRunner::default(); standalone.init_evm(); @@ -29,13 +29,13 @@ fn test_prepaid_gas_precompile() { assert_eq!( U256::from(EXPECTED_VALUE), - U256::from_big_endian(test_utils::unwrap_success_slice(&result)), + U256::from_big_endian(utils::unwrap_success_slice(&result)), ); // confirm the precompile works in view calls too - let sender = test_utils::address_from_secret_key(&signer.secret_key); + let sender = utils::address_from_secret_key(&signer.secret_key); let result = runner - .view_call(&test_utils::as_view_call(transaction, sender)) + .view_call(&utils::as_view_call(transaction, sender)) .unwrap(); assert!(result.is_ok()); } diff --git a/engine-tests/src/tests/promise_results_precompile.rs b/engine-tests/src/tests/promise_results_precompile.rs index 3d28de702..14c39f764 100644 --- a/engine-tests/src/tests/promise_results_precompile.rs +++ b/engine-tests/src/tests/promise_results_precompile.rs @@ -1,18 +1,18 @@ -use crate::test_utils::{self, standalone}; +use crate::utils::{self, standalone}; use aurora_engine_precompiles::promise_result::{self, costs}; use aurora_engine_transactions::legacy::TransactionLegacy; +use aurora_engine_types::borsh::BorshSerialize; use aurora_engine_types::{ types::{Address, EthGas, NearGas, PromiseResult, Wei}, U256, }; -use borsh::BorshSerialize; const NEAR_GAS_PER_EVM: u64 = 175_000_000; #[test] fn test_promise_results_precompile() { - let mut signer = test_utils::Signer::random(); - let mut runner = test_utils::deploy_evm(); + let mut signer = utils::Signer::random(); + let mut runner = utils::deploy_runner(); let mut standalone = standalone::StandaloneRunner::default(); standalone.init_evm(); @@ -43,18 +43,18 @@ fn test_promise_results_precompile() { assert_eq!(result, standalone_result); assert_eq!( - test_utils::unwrap_success(result), + utils::unwrap_success(result), promise_results.try_to_vec().unwrap(), ); } #[test] fn test_promise_result_gas_cost() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut standalone = standalone::StandaloneRunner::default(); standalone.init_evm(); runner.standalone_runner = Some(standalone); - let mut signer = test_utils::Signer::random(); + let mut signer = utils::Signer::random(); runner.context.block_height = aurora_engine::engine::ZERO_ADDRESS_FIX_HEIGHT + 1; // Baseline transaction that does essentially nothing. @@ -107,7 +107,7 @@ fn test_promise_result_gas_cost() { let cost_per_byte = cost_per_byte / NEAR_GAS_PER_EVM; assert!( - test_utils::within_x_percent( + utils::within_x_percent( 5, base_cost.as_u64(), costs::PROMISE_RESULT_BASE_COST.as_u64() @@ -118,7 +118,7 @@ fn test_promise_result_gas_cost() { ); assert!( - test_utils::within_x_percent(5, cost_per_byte, costs::PROMISE_RESULT_BYTE_COST.as_u64()), + utils::within_x_percent(5, cost_per_byte, costs::PROMISE_RESULT_BYTE_COST.as_u64()), "Incorrect promise_result per byte cost. Expected: {} Actual: {}", cost_per_byte, costs::PROMISE_RESULT_BYTE_COST @@ -127,13 +127,13 @@ fn test_promise_result_gas_cost() { let total_gas1 = y1 + baseline.all_gas(); let total_gas2 = y2 + baseline.all_gas(); assert!( - test_utils::within_x_percent(6, evm1, total_gas1 / NEAR_GAS_PER_EVM), + utils::within_x_percent(6, evm1, total_gas1 / NEAR_GAS_PER_EVM), "Incorrect EVM gas used. Expected: {} Actual: {}", evm1, total_gas1 / NEAR_GAS_PER_EVM ); assert!( - test_utils::within_x_percent(6, evm2, total_gas2 / NEAR_GAS_PER_EVM), + utils::within_x_percent(6, evm2, total_gas2 / NEAR_GAS_PER_EVM), "Incorrect EVM gas used. Expected: {} Actual: {}", evm2, total_gas2 / NEAR_GAS_PER_EVM diff --git a/engine-tests/src/tests/random.rs b/engine-tests/src/tests/random.rs index dfc1e1df9..473887ab1 100644 --- a/engine-tests/src/tests/random.rs +++ b/engine-tests/src/tests/random.rs @@ -1,12 +1,12 @@ -use crate::test_utils; -use crate::test_utils::random::{Random, RandomConstructor}; +use crate::utils; +use crate::utils::solidity::random::{Random, RandomConstructor}; use aurora_engine_types::H256; #[test] fn test_random_number_precompile() { let random_seed = H256::from_slice(vec![7; 32].as_slice()); - let mut signer = test_utils::Signer::random(); - let mut runner = test_utils::deploy_evm().with_random_seed(random_seed); + let mut signer = utils::Signer::random(); + let mut runner = utils::deploy_runner().with_random_seed(random_seed); let random_ctr = RandomConstructor::load(); let nonce = signer.use_nonce(); diff --git a/engine-tests/src/tests/repro.rs b/engine-tests/src/tests/repro.rs index 3d4d37c6c..d69bdbf0d 100644 --- a/engine-tests/src/tests/repro.rs +++ b/engine-tests/src/tests/repro.rs @@ -1,9 +1,9 @@ //! A module containing tests which reproduce transactions sent to live networks. -use crate::test_utils::{standalone, ORIGIN}; -use crate::test_utils::{AuroraRunner, ExecutionProfile}; +use crate::utils::{standalone, ORIGIN}; +use crate::utils::{AuroraRunner, ExecutionProfile}; use aurora_engine::parameters::SubmitResult; -use borsh::{BorshDeserialize, BorshSerialize}; +use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize}; use engine_standalone_storage::json_snapshot; /// This test reproduces a transaction from testnet: diff --git a/engine-tests/src/tests/sanity.rs b/engine-tests/src/tests/sanity.rs index 8ae1dbd89..c729cfac4 100644 --- a/engine-tests/src/tests/sanity.rs +++ b/engine-tests/src/tests/sanity.rs @@ -1,19 +1,14 @@ use crate::prelude::{Address, U256}; use crate::prelude::{Wei, ERC20_MINT_SELECTOR}; -use crate::test_utils::{self, str_to_account_id}; -use crate::tests::state_migration; +use crate::utils::{self, str_to_account_id}; use aurora_engine::engine::{EngineErrorKind, GasPaymentError, ZERO_ADDRESS_FIX_HEIGHT}; use aurora_engine::fungible_token::FungibleTokenMetadata; -use aurora_engine::parameters::{ - SetOwnerArgs, SetUpgradeDelayBlocksArgs, SubmitResult, TransactionStatus, -}; +use aurora_engine::parameters::{SetOwnerArgs, SetUpgradeDelayBlocksArgs, TransactionStatus}; use aurora_engine_sdk as sdk; +use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize}; use aurora_engine_types::H160; -use borsh::{BorshDeserialize, BorshSerialize}; use evm::ExitFatal; use libsecp256k1::SecretKey; -use near_sdk_sim::errors::TxExecutionError; -use near_sdk_sim::transaction::ExecutionStatus; use rand::RngCore; use std::path::{Path, PathBuf}; @@ -26,16 +21,16 @@ const GAS_PRICE: u64 = 10; fn test_total_supply_accounting() { let (mut runner, mut signer, benefactor) = initialize_transfer(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "self_destructor.sol", "SelfDestruct", ); - let deploy_contract = |runner: &mut test_utils::AuroraRunner, - signer: &mut test_utils::Signer| - -> test_utils::solidity::DeployedContract { + let deploy_contract = |runner: &mut utils::AuroraRunner, + signer: &mut utils::Signer| + -> utils::solidity::DeployedContract { let submit_result = runner .submit_with_signer(signer, |nonce| { let mut deploy_tx = constructor.deploy_without_constructor(nonce); @@ -45,11 +40,11 @@ fn test_total_supply_accounting() { .unwrap(); let contract_address = - Address::try_from_slice(test_utils::unwrap_success_slice(&submit_result)).unwrap(); + Address::try_from_slice(utils::unwrap_success_slice(&submit_result)).unwrap(); constructor.deployed_at(contract_address) }; - let get_total_supply = |runner: &mut test_utils::AuroraRunner| -> Wei { + let get_total_supply = |runner: &mut utils::AuroraRunner| -> Wei { let result = runner.call("ft_total_eth_supply_on_aurora", "aurora", Vec::new()); let amount: u128 = String::from_utf8(result.unwrap().return_data.as_value().unwrap()) .unwrap() @@ -110,25 +105,21 @@ fn test_transaction_to_zero_address() { // We want the standalone engine to still reproduce the old behaviour for blocks before the bug fix, and // to use the correct parsing for blocks after the fix. - let mut runner = test_utils::standalone::StandaloneRunner::default(); + let mut runner = utils::standalone::StandaloneRunner::default(); runner.init_evm_with_chain_id(normalized_tx.chain_id.unwrap()); - let mut context = test_utils::AuroraRunner::default().context; + let mut context = utils::AuroraRunner::default().context; context.input = tx_bytes; // Prior to the fix the zero address is interpreted as None, causing a contract deployment. // It also incorrectly derives the sender address, so does not increment the right nonce. context.block_height = ZERO_ADDRESS_FIX_HEIGHT - 1; - let result = runner - .submit_raw(test_utils::SUBMIT, &context, &[]) - .unwrap(); + let result = runner.submit_raw(utils::SUBMIT, &context, &[]).unwrap(); assert_eq!(result.gas_used, 53_000); runner.env.block_height = ZERO_ADDRESS_FIX_HEIGHT; assert_eq!(runner.get_nonce(&address), U256::zero()); // After the fix this transaction is simply a transfer of 0 ETH to the zero address context.block_height = ZERO_ADDRESS_FIX_HEIGHT; - let result = runner - .submit_raw(test_utils::SUBMIT, &context, &[]) - .unwrap(); + let result = runner.submit_raw(utils::SUBMIT, &context, &[]).unwrap(); assert_eq!(result.gas_used, 21_000); runner.env.block_height = ZERO_ADDRESS_FIX_HEIGHT + 1; assert_eq!(runner.get_nonce(&address), U256::one()); @@ -171,10 +162,10 @@ fn test_deploy_contract() { // Deploy that code let result = runner .submit_with_signer(&mut signer, |nonce| { - test_utils::create_deploy_transaction(code.clone(), nonce) + utils::create_deploy_transaction(code.clone(), nonce) }) .unwrap(); - let address = Address::try_from_slice(test_utils::unwrap_success_slice(&result)).unwrap(); + let address = Address::try_from_slice(utils::unwrap_success_slice(&result)).unwrap(); // Confirm the code stored at that address is equal to the input code. let stored_code = runner.get_code(address); @@ -193,7 +184,7 @@ fn test_deploy_largest_contract() { // Deploy that code let (result, profile) = runner .submit_with_signer_profiled(&mut signer, |nonce| { - test_utils::create_deploy_transaction(code.clone(), nonce) + utils::create_deploy_transaction(code.clone(), nonce) }) .unwrap(); @@ -205,15 +196,15 @@ fn test_deploy_largest_contract() { ); // Less than 12 NEAR Tgas - test_utils::assert_gas_bound(profile.all_gas(), 10); + utils::assert_gas_bound(profile.all_gas(), 10); } #[test] fn test_log_address() { let (mut runner, mut signer, _) = initialize_transfer(); - let mut deploy_contract = |name: &str, signer: &mut test_utils::Signer| { - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let mut deploy_contract = |name: &str, signer: &mut utils::Signer| { + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "caller.sol", @@ -250,9 +241,9 @@ fn test_log_address() { #[test] fn test_is_contract() { let (mut runner, mut signer, _) = initialize_transfer(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let signer_address = utils::address_from_secret_key(&signer.secret_key); - let constructor = test_utils::solidity::ContractConstructor::force_compile( + let constructor = utils::solidity::ContractConstructor::force_compile( "src/tests/res", "target/solidity_build", "is_contract.sol", @@ -266,27 +257,25 @@ fn test_is_contract() { constructor, ); - let call_contract = |account: Address, - runner: &mut test_utils::AuroraRunner, - signer: &mut test_utils::Signer| - -> bool { - let result = runner - .submit_with_signer(signer, |nonce| { - contract.call_method_with_args( - "isContract", - &[ethabi::Token::Address(account.raw())], - nonce, - ) - }) - .unwrap(); - let bytes = test_utils::unwrap_success_slice(&result); - ethabi::decode(&[ethabi::ParamType::Bool], bytes) - .unwrap() - .pop() - .unwrap() - .into_bool() - .unwrap() - }; + let call_contract = + |account: Address, runner: &mut utils::AuroraRunner, signer: &mut utils::Signer| -> bool { + let result = runner + .submit_with_signer(signer, |nonce| { + contract.call_method_with_args( + "isContract", + &[ethabi::Token::Address(account.raw())], + nonce, + ) + }) + .unwrap(); + let bytes = utils::unwrap_success_slice(&result); + ethabi::decode(&[ethabi::ParamType::Bool], bytes) + .unwrap() + .pop() + .unwrap() + .into_bool() + .unwrap() + }; // Should return false for accounts that don't exist assert!(!call_contract( @@ -299,7 +288,7 @@ fn test_is_contract() { assert!(!call_contract(signer_address, &mut runner, &mut signer),); // Should return true for contracts - let erc20_constructor = test_utils::erc20::ERC20Constructor::load(); + let erc20_constructor = utils::solidity::erc20::ERC20Constructor::load(); let nonce = signer.use_nonce(); let token_a = runner.deploy_contract( &signer.secret_key, @@ -314,7 +303,7 @@ fn test_solidity_pure_bench() { let (mut runner, mut signer, _) = initialize_transfer(); runner.wasm_config.limit_config.max_gas_burnt = u64::MAX; - let constructor = test_utils::solidity::ContractConstructor::force_compile( + let constructor = utils::solidity::ContractConstructor::force_compile( "src/tests/res", "target/solidity_build", "bench.sol", @@ -355,7 +344,7 @@ fn test_solidity_pure_bench() { let base_path = Path::new("../etc").join("tests").join("benchmark-contract"); let output_path = base_path.join("target/wasm32-unknown-unknown/release/benchmark_contract.wasm"); - test_utils::rust::compile(base_path); + utils::rust::compile(base_path); let contract_bytes = std::fs::read(output_path).unwrap(); let code = near_primitives_core::contract::ContractCode::new(contract_bytes, None); let mut context = runner.context.clone(); @@ -372,7 +361,7 @@ fn test_solidity_pure_bench() { Some(&runner.cache), ) .unwrap(); - let profile = test_utils::ExecutionProfile::new(&outcome); + let profile = utils::ExecutionProfile::new(&outcome); // Check the contract actually did the work. assert_eq!(&outcome.logs, &[format!("Done {loop_limit} iterations!")]); @@ -383,7 +372,7 @@ fn test_solidity_pure_bench() { fn test_revert_during_contract_deploy() { let (mut runner, mut signer, _) = initialize_transfer(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "reverter.sol", @@ -397,7 +386,7 @@ fn test_revert_during_contract_deploy() { .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); - let revert_bytes = test_utils::unwrap_revert(submit_result); + let revert_bytes = utils::unwrap_revert_slice(&submit_result); // First 4 bytes is a function selector with signature `Error(string)` assert_eq!(&revert_bytes[0..4], &[8, 195, 121, 160]); // Remaining data is an ABI-encoded string @@ -415,7 +404,7 @@ fn test_revert_during_contract_deploy() { fn test_call_too_deep_error() { let (mut runner, mut signer, _) = initialize_transfer(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "CallTooDeep.sol", @@ -478,7 +467,7 @@ fn test_create_out_of_gas() { fn test_timestamp() { let (mut runner, mut signer, _) = initialize_transfer(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let constructor = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "timestamp.sol", @@ -507,7 +496,7 @@ fn test_timestamp() { contract.call_method_without_args("getCurrentBlockTimestamp", nonce) }) .unwrap(); - let timestamp = U256::from_big_endian(&test_utils::unwrap_success(result)); + let timestamp = U256::from_big_endian(&utils::unwrap_success(result)); // Check time is correct. // The `+1` is needed here because the runner increments the context @@ -518,12 +507,12 @@ fn test_timestamp() { #[test] fn test_override_state() { let (mut runner, mut account1, viewer_address) = initialize_transfer(); - let account1_address = test_utils::address_from_secret_key(&account1.secret_key); - let mut account2 = test_utils::Signer::random(); - let account2_address = test_utils::address_from_secret_key(&account2.secret_key); + let account1_address = utils::address_from_secret_key(&account1.secret_key); + let mut account2 = utils::Signer::random(); + let account2_address = utils::address_from_secret_key(&account2.secret_key); runner.create_address(account2_address, INITIAL_BALANCE, INITIAL_NONCE.into()); - let contract = test_utils::solidity::ContractConstructor::compile_from_source( + let contract = utils::solidity::ContractConstructor::compile_from_source( "src/tests/res", "target/solidity_build", "poster.sol", @@ -543,13 +532,13 @@ fn test_override_state() { } }) .unwrap(); - let address = Address::try_from_slice(&test_utils::unwrap_success(result)).unwrap(); + let address = Address::try_from_slice(&utils::unwrap_success(result)).unwrap(); let contract = contract.deployed_at(address); // define functions to interact with the contract - let get_address = |runner: &test_utils::AuroraRunner| { + let get_address = |runner: &utils::AuroraRunner| { let result = runner - .view_call(&test_utils::as_view_call( + .view_call(&utils::as_view_call( contract.call_method_without_args("get", U256::zero()), viewer_address, )) @@ -560,7 +549,7 @@ fn test_override_state() { } }; - let post_address = |runner: &mut test_utils::AuroraRunner, signer: &mut test_utils::Signer| { + let post_address = |runner: &mut utils::AuroraRunner, signer: &mut utils::Signer| { let result = runner .submit_with_signer(signer, |nonce| { contract.call_method_with_args( @@ -587,7 +576,7 @@ fn test_override_state() { fn test_num_wasm_functions() { // Counts the number of functions in our wasm output. // See https://github.com/near/nearcore/issues/4814 for context - let runner = test_utils::deploy_evm(); + let runner = utils::deploy_runner(); let module = walrus::ModuleConfig::default() .parse(runner.code.code()) .unwrap(); @@ -604,126 +593,121 @@ fn test_num_wasm_functions() { fn test_eth_transfer_success() { // set up Aurora runner and accounts let (mut runner, mut source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // perform transfer runner .submit_with_signer(&mut source_account, |nonce| { - test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce) + utils::transfer(dest_address, TRANSFER_AMOUNT, nonce) }) .unwrap(); // validate post-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE - TRANSFER_AMOUNT, (INITIAL_NONCE + 1).into(), ); - test_utils::validate_address_balance_and_nonce( - &runner, - dest_address, - TRANSFER_AMOUNT, - 0.into(), - ); + utils::validate_address_balance_and_nonce(&runner, dest_address, TRANSFER_AMOUNT, 0.into()); } /// Tests the case where the transfer amount is larger than the address balance #[test] fn test_eth_transfer_insufficient_balance() { let (mut runner, mut source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer let result = runner .submit_with_signer(&mut source_account, |nonce| { // try to transfer more than we have - test_utils::transfer(dest_address, INITIAL_BALANCE + INITIAL_BALANCE, nonce) + utils::transfer(dest_address, INITIAL_BALANCE + INITIAL_BALANCE, nonce) }) .unwrap(); assert_eq!(result.status, TransactionStatus::OutOfFund); // validate post-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, // the nonce is still incremented even though the transfer failed (INITIAL_NONCE + 1).into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); } /// Tests the case where the nonce on the transaction does not match the address #[test] fn test_eth_transfer_incorrect_nonce() { let (mut runner, mut source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer let error = runner .submit_with_signer(&mut source_account, |nonce| { // creating transaction with incorrect nonce - test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce + 1) + utils::transfer(dest_address, TRANSFER_AMOUNT, nonce + 1) }) .unwrap_err(); assert_eq!(error.kind, EngineErrorKind::IncorrectNonce); // validate post-state (which is the same as pre-state in this case) - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); } #[test] fn test_eth_transfer_not_enough_gas() { let (mut runner, mut source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); let transaction = |nonce| { - let mut tx = test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); + let mut tx = utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); tx.gas_limit = 10_000.into(); // this is not enough gas tx }; // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer let error = runner @@ -732,34 +716,34 @@ fn test_eth_transfer_not_enough_gas() { assert_eq!(error.kind, EngineErrorKind::IntrinsicGasNotMet); // validate post-state (which is the same as pre-state in this case) - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); } #[test] fn test_transfer_charging_gas_success() { let (mut runner, mut source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); let transaction = |nonce| { - let mut tx = test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); + let mut tx = utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); tx.gas_limit = 30_000.into(); tx.gas_price = GAS_PRICE.into(); tx }; // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // do transfer let result = runner @@ -774,19 +758,19 @@ fn test_transfer_charging_gas_success() { ); // validate post-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, expected_source_balance, (INITIAL_NONCE + 1).into(), ); - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, dest_address, expected_dest_balance, 0.into(), ); - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, relayer_address, expected_relayer_balance, @@ -797,9 +781,9 @@ fn test_transfer_charging_gas_success() { #[test] fn test_eth_transfer_charging_gas_not_enough_balance() { let (mut runner, mut source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); let transaction = |nonce| { - let mut tx = test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); + let mut tx = utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); // With this gas limit and price the account does not // have enough balance to cover the gas cost tx.gas_limit = 3_000_000.into(); @@ -808,13 +792,13 @@ fn test_eth_transfer_charging_gas_not_enough_balance() { }; // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer let error = runner @@ -830,26 +814,26 @@ fn test_eth_transfer_charging_gas_not_enough_balance() { runner.context.predecessor_account_id.as_ref().as_bytes(), ); - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, // nonce is still not incremented since the transaction was invalid INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); - test_utils::validate_address_balance_and_nonce(&runner, relayer, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, relayer, Wei::zero(), 0.into()); } -pub fn initialize_transfer() -> (test_utils::AuroraRunner, test_utils::Signer, Address) { +pub fn initialize_transfer() -> (utils::AuroraRunner, utils::Signer, Address) { // set up Aurora runner and accounts - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut rng = rand::thread_rng(); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); runner.create_address(source_address, INITIAL_BALANCE, INITIAL_NONCE.into()); - let dest_address = test_utils::address_from_secret_key(&SecretKey::random(&mut rng)); - let mut signer = test_utils::Signer::new(source_account); + let dest_address = utils::address_from_secret_key(&SecretKey::random(&mut rng)); + let mut signer = utils::Signer::new(source_account); signer.nonce = INITIAL_NONCE; (runner, signer, dest_address) @@ -857,7 +841,7 @@ pub fn initialize_transfer() -> (test_utils::AuroraRunner, test_utils::Signer, A #[test] fn check_selector() { - // Selector to call mint function in ERC 20 contract + // Selector to call mint function in ERC-20 contract // // keccak("mint(address,uint256)".as_bytes())[..4]; use sha3::Digest; @@ -868,7 +852,7 @@ fn check_selector() { #[test] fn test_block_hash() { - let runner = test_utils::AuroraRunner::default(); + let runner = utils::AuroraRunner::default(); let chain_id = { let number = crate::prelude::U256::from(runner.chain_id); crate::prelude::u256_to_arr(&number) @@ -884,7 +868,7 @@ fn test_block_hash() { #[test] fn test_block_hash_api() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let block_height: u64 = 10; let outcome = runner .call( @@ -904,7 +888,7 @@ fn test_block_hash_api() { #[test] fn test_block_hash_contract() { let (mut runner, mut source_account, _) = initialize_transfer(); - let test_constructor = test_utils::solidity::ContractConstructor::compile_from_source( + let test_constructor = utils::solidity::ContractConstructor::compile_from_source( ["src", "tests", "res"].iter().collect::(), Path::new("target").join("solidity_build"), "blockhash.sol", @@ -923,12 +907,12 @@ fn test_block_hash_contract() { }) .unwrap(); - test_utils::panic_on_fail(result.status); + utils::panic_on_fail(result.status); } #[test] fn test_ft_metadata() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let account_id: String = runner.context.signer_account_id.clone().into(); let outcome = runner.call("ft_metadata", &account_id, Vec::new()).unwrap(); let metadata = @@ -938,100 +922,25 @@ fn test_ft_metadata() { assert_eq!(metadata, FungibleTokenMetadata::default()); } -// Same as `test_eth_transfer_insufficient_balance` above, except runs through -// `near-sdk-sim` instead of `near-vm-runner`. This is important because `near-sdk-sim` -// has more production logic, in particular, state revert on contract panic. -// TODO: should be able to generalize the `call` backend of `AuroraRunner` so that this -// test does not need to be written twice. -#[test] -fn test_eth_transfer_insufficient_balance_sim() { - let (aurora, mut signer, address) = initialize_evm_sim(); - - // Run transaction which will fail (transfer more than current balance) - let nonce = signer.use_nonce(); - let tx = test_utils::transfer( - Address::new(H160([1; 20])), - INITIAL_BALANCE + INITIAL_BALANCE, - nonce.into(), - ); - let signed_tx = test_utils::sign_transaction( - tx, - Some(test_utils::AuroraRunner::default().chain_id), - &signer.secret_key, - ); - let call_result = aurora.call("submit", rlp::encode(&signed_tx).as_ref()); - let result = match call_result.status() { - ExecutionStatus::SuccessValue(bytes) => { - use borsh::BorshDeserialize; - SubmitResult::try_from_slice(&bytes).unwrap() - } - other => panic!("Unexpected status {other:?}"), - }; - assert_eq!(result.status, TransactionStatus::OutOfFund); - - // validate post-state - assert_eq!( - query_address_sim(&address, "get_nonce", &aurora), - U256::from(INITIAL_NONCE + 1), - ); - assert_eq!( - query_address_sim(&address, "get_balance", &aurora), - INITIAL_BALANCE.raw(), - ); -} - -// Same as `test_eth_transfer_charging_gas_not_enough_balance` but run through `near-sdk-sim`. -#[test] -fn test_eth_transfer_charging_gas_not_enough_balance_sim() { - let (aurora, mut signer, address) = initialize_evm_sim(); - - // Run transaction which will fail (not enough balance to cover gas) - let nonce = signer.use_nonce(); - let mut tx = test_utils::transfer(Address::new(H160([1; 20])), TRANSFER_AMOUNT, nonce.into()); - tx.gas_limit = 3_000_000.into(); - tx.gas_price = GAS_PRICE.into(); - let signed_tx = test_utils::sign_transaction( - tx, - Some(test_utils::AuroraRunner::default().chain_id), - &signer.secret_key, - ); - let call_result = aurora.call("submit", rlp::encode(&signed_tx).as_ref()); - let outcome = call_result.outcome(); - - assert!(matches!(&outcome.status, ExecutionStatus::Failure( - TxExecutionError::ActionError(e)) if e.to_string().contains("ERR_OUT_OF_FUND") - )); - - // validate post-state - assert_eq!( - query_address_sim(&address, "get_nonce", &aurora), - INITIAL_NONCE.into(), // nonce hasn't been changed because an error occurs - ); - assert_eq!( - query_address_sim(&address, "get_balance", &aurora), - INITIAL_BALANCE.raw(), - ); -} - /// Tests transfer Eth from one account to another with custom argument `max_gas_price`. #[test] fn test_eth_transfer_with_max_gas_price() { // set up Aurora runner and accounts let (mut runner, source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let source_address = utils::address_from_secret_key(&source_account.secret_key); // validate pre-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE, INITIAL_NONCE.into(), ); - test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); + utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // perform transfer let max_gas_price = 5; - let mut transaction = test_utils::transfer(dest_address, TRANSFER_AMOUNT, INITIAL_NONCE.into()); + let mut transaction = utils::transfer(dest_address, TRANSFER_AMOUNT, INITIAL_NONCE.into()); transaction.gas_price = 10.into(); transaction.gas_limit = 30_000.into(); @@ -1041,23 +950,18 @@ fn test_eth_transfer_with_max_gas_price() { let fee = u128::from(result.gas_used) * max_gas_price; // validate post-state - test_utils::validate_address_balance_and_nonce( + utils::validate_address_balance_and_nonce( &runner, source_address, INITIAL_BALANCE - TRANSFER_AMOUNT - Wei::new_u128(fee), (INITIAL_NONCE + 1).into(), ); - test_utils::validate_address_balance_and_nonce( - &runner, - dest_address, - TRANSFER_AMOUNT, - 0.into(), - ); + utils::validate_address_balance_and_nonce(&runner, dest_address, TRANSFER_AMOUNT, 0.into()); } #[test] fn test_set_owner() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); // set owner args @@ -1088,7 +992,7 @@ fn test_set_owner() { #[test] fn test_set_owner_fail_on_same_owner() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); // set owner args @@ -1113,7 +1017,7 @@ fn test_set_owner_fail_on_same_owner() { #[test] fn test_set_upgrade_delay_blocks() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let aurora_account_id = runner.aurora_account_id.clone(); // set upgrade_delay_blocks args @@ -1144,37 +1048,107 @@ fn test_set_upgrade_delay_blocks() { assert_eq!(result.upgrade_delay_blocks, 2); } -fn initialize_evm_sim() -> (state_migration::AuroraAccount, test_utils::Signer, Address) { - let aurora = state_migration::deploy_evm(); - let signer = test_utils::Signer::random(); - let address = test_utils::address_from_secret_key(&signer.secret_key); +mod workspace { + use crate::prelude::{Address, U256}; + use crate::tests::sanity::{GAS_PRICE, INITIAL_BALANCE, INITIAL_NONCE, TRANSFER_AMOUNT}; + use crate::utils; + use aurora_engine_types::parameters::engine::TransactionStatus; + use aurora_engine_workspace::EngineContract; + + // Same as `test_eth_transfer_insufficient_balance` above, except runs through + // `aurora-engine-workspace` instead of `near-vm-runner`. This is important because + // `aurora-engine-workspace` has more production logic, in particular, state revert on + // contract panic. + // TODO: should be able to generalize the `call` backend of `AuroraRunner` so that this + // test does not need to be written twice. + #[tokio::test] + async fn test_eth_transfer_insufficient_balance() { + let (aurora, mut signer, address) = initialize_engine().await; + + // Run transaction which will fail (transfer more than current balance) + let nonce = signer.use_nonce(); + let tx = utils::transfer( + Address::from_array([1; 20]), + INITIAL_BALANCE + INITIAL_BALANCE, + nonce.into(), + ); + let signed_tx = utils::sign_transaction( + tx, + Some(utils::AuroraRunner::default().chain_id), + &signer.secret_key, + ); + let result = aurora + .submit(rlp::encode(&signed_tx).to_vec()) + .transact() + .await + .unwrap() + .into_value(); + assert_eq!(result.status, TransactionStatus::OutOfFund); - let args = (address, INITIAL_NONCE, INITIAL_BALANCE.raw().low_u64()); - aurora - .call("mint_account", &args.try_to_vec().unwrap()) - .assert_success(); + // validate post-state + assert_eq!( + aurora.get_nonce(address).await.unwrap().result, + (INITIAL_NONCE + 1).into(), + ); + assert_eq!( + aurora.get_balance(address).await.unwrap().result, + INITIAL_BALANCE.raw(), + ); + } - // validate pre-state - assert_eq!( - query_address_sim(&address, "get_nonce", &aurora), - U256::from(INITIAL_NONCE), - ); - assert_eq!( - query_address_sim(&address, "get_balance", &aurora), - INITIAL_BALANCE.raw(), - ); + // Same as `test_eth_transfer_charging_gas_not_enough_balance` but run through + // `aurora-engine-workspace`. + #[tokio::test] + async fn test_eth_transfer_charging_gas_not_enough_balance() { + let (aurora, mut signer, address) = initialize_engine().await; - (aurora, signer, address) -} + // Run transaction which will fail (not enough balance to cover gas) + let nonce = signer.use_nonce(); + let mut tx = utils::transfer(Address::from_array([1; 20]), TRANSFER_AMOUNT, nonce.into()); + tx.gas_limit = 3_000_000.into(); + tx.gas_price = GAS_PRICE.into(); + let signed_tx = utils::sign_transaction( + tx, + Some(utils::AuroraRunner::default().chain_id), + &signer.secret_key, + ); + let error = aurora + .submit(rlp::encode(&signed_tx).to_vec()) + .transact() + .await + .err() + .unwrap(); + assert!(error.to_string().contains("ERR_OUT_OF_FUND")); + + // validate post-state + assert_eq!( + aurora.get_nonce(address).await.unwrap().result, + INITIAL_NONCE.into(), // nonce hasn't been changed because an error occurs + ); + assert_eq!( + aurora.get_balance(address).await.unwrap().result, + INITIAL_BALANCE.raw(), + ); + } + async fn initialize_engine() -> (EngineContract, utils::Signer, Address) { + let engine = utils::workspace::deploy_engine().await; + let signer = utils::Signer::random(); + let address = utils::address_from_secret_key(&signer.secret_key); + let result = engine + .mint_account(address, INITIAL_NONCE, INITIAL_BALANCE.raw().low_u64()) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); + + // validate pre-state + let nonce = engine.get_nonce(address).await.unwrap(); + assert_eq!(nonce.result, U256::from(INITIAL_NONCE),); + + let balance = engine.get_balance(address).await.unwrap(); + assert_eq!(balance.result, INITIAL_BALANCE.raw(),); -fn query_address_sim( - address: &Address, - method: &str, - aurora: &state_migration::AuroraAccount, -) -> U256 { - let x = aurora.call(method, address.as_bytes()); - match &x.outcome().status { - ExecutionStatus::SuccessValue(b) => U256::from_big_endian(b), - other => panic!("Unexpected outcome: {other:?}"), + (engine, signer, address) } } diff --git a/engine-tests/src/tests/self_destruct_state.rs b/engine-tests/src/tests/self_destruct_state.rs index 116552d2c..480f51f62 100644 --- a/engine-tests/src/tests/self_destruct_state.rs +++ b/engine-tests/src/tests/self_destruct_state.rs @@ -1,13 +1,13 @@ -use crate::test_utils; -use crate::test_utils::self_destruct::{ +use crate::utils; +use crate::utils::solidity::self_destruct::{ SelfDestruct, SelfDestructConstructor, SelfDestructFactory, SelfDestructFactoryConstructor, }; /// Check that account state should be properly removed after calling selfdestruct #[test] fn test_self_destruct_reset_state() { - let mut signer = test_utils::Signer::random(); - let mut runner = test_utils::deploy_evm(); + let mut signer = utils::Signer::random(); + let mut runner = utils::deploy_runner(); let sd_factory_ctr = SelfDestructFactoryConstructor::load(); let nonce = signer.use_nonce(); @@ -40,8 +40,8 @@ fn test_self_destruct_reset_state() { #[test] fn test_self_destruct_with_submit() { - let mut signer = test_utils::Signer::random(); - let mut runner = test_utils::deploy_evm(); + let mut signer = utils::Signer::random(); + let mut runner = utils::deploy_runner(); let sd_factory_ctr = SelfDestructFactoryConstructor::load(); let nonce = signer.use_nonce(); diff --git a/engine-tests/src/tests/standalone/call_tracer.rs b/engine-tests/src/tests/standalone/call_tracer.rs index 00a19761e..4880063a2 100644 --- a/engine-tests/src/tests/standalone/call_tracer.rs +++ b/engine-tests/src/tests/standalone/call_tracer.rs @@ -1,13 +1,14 @@ use crate::prelude::H256; -use crate::test_utils::{self, standalone}; +use crate::utils::solidity::erc20::{ERC20Constructor, ERC20}; +use crate::utils::{self, standalone, Signer}; use aurora_engine_modexp::AuroraModExp; +use aurora_engine_types::borsh::BorshSerialize; use aurora_engine_types::{ parameters::{CrossContractCallArgs, PromiseArgs, PromiseCreateArgs}, storage, types::{Address, NearGas, Wei, Yocto}, U256, }; -use borsh::BorshSerialize; use engine_standalone_storage::sync; use engine_standalone_tracing::{ sputnik, @@ -17,11 +18,11 @@ use engine_standalone_tracing::{ #[test] fn test_trace_contract_deploy() { let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); + let mut signer = Signer::random(); runner.init_evm(); - let constructor = test_utils::erc20::ERC20Constructor::load(); + let constructor = ERC20Constructor::load(); let deploy_tx = constructor.deploy("Test", "TST", signer.use_nonce().into()); let mut listener = CallTracer::default(); let deploy_result = sputnik::traced_call(&mut listener, || { @@ -30,7 +31,7 @@ fn test_trace_contract_deploy() { .unwrap() }); let contract_address = { - let bytes = test_utils::unwrap_success_slice(&deploy_result); + let bytes = utils::unwrap_success_slice(&deploy_result); Address::try_from_slice(bytes).unwrap() }; let code = runner.get_code(&contract_address); @@ -45,7 +46,7 @@ fn test_trace_contract_deploy() { #[test] fn test_trace_precompile_direct_call() { let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); + let mut signer = Signer::random(); runner.init_evm(); @@ -69,7 +70,7 @@ fn test_trace_precompile_direct_call() { let expected_trace = call_tracer::CallFrame { call_type: call_tracer::CallType::Call, - from: test_utils::address_from_secret_key(&signer.secret_key), + from: utils::address_from_secret_key(&signer.secret_key), to: Some(aurora_engine_precompiles::random::RandomSeed::ADDRESS), value: U256::zero(), gas: u64::MAX, @@ -88,21 +89,21 @@ fn test_trace_precompile_direct_call() { #[test] fn test_trace_contract_single_call() { let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let mut signer = Signer::random(); + let signer_address = utils::address_from_secret_key(&signer.secret_key); runner.init_evm(); - let constructor = test_utils::erc20::ERC20Constructor::load(); + let constructor = ERC20Constructor::load(); let deploy_tx = constructor.deploy("Test", "TST", signer.use_nonce().into()); let deploy_result = runner .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); let contract_address = { - let bytes = test_utils::unwrap_success_slice(&deploy_result); + let bytes = utils::unwrap_success_slice(&deploy_result); Address::try_from_slice(bytes).unwrap() }; - let contract = test_utils::erc20::ERC20(constructor.0.deployed_at(contract_address)); + let contract = ERC20(constructor.0.deployed_at(contract_address)); let tx = contract.balance_of(signer_address, signer.use_nonce().into()); let mut listener = CallTracer::default(); @@ -165,7 +166,7 @@ fn test_trace_contract_with_sub_call() { assert_eq!(listener.call_stack.len(), 1); - let user_address = test_utils::address_from_secret_key(&context.signer.secret_key); + let user_address = utils::address_from_secret_key(&context.signer.secret_key); let router_address = context.swap_router.0.address; let pool_address = pool.0.address; let b_address = token_b.0.address; @@ -208,20 +209,20 @@ fn test_trace_contract_with_sub_call() { #[test] fn test_trace_contract_with_precompile_sub_call() { let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); + let mut signer = Signer::random(); runner.init_evm(); - let constructor = test_utils::standard_precompiles::PrecompilesConstructor::load(); + let constructor = utils::solidity::standard_precompiles::PrecompilesConstructor::load(); let deploy_tx = constructor.deploy(signer.use_nonce().into()); let deploy_result = runner .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); let contract_address = { - let bytes = test_utils::unwrap_success_slice(&deploy_result); + let bytes = utils::unwrap_success_slice(&deploy_result); Address::try_from_slice(bytes).unwrap() }; - let contract = test_utils::standard_precompiles::PrecompilesContract( + let contract = utils::solidity::standard_precompiles::PrecompilesContract( constructor.0.deployed_at(contract_address), ); @@ -252,24 +253,24 @@ fn test_trace_precompiles_with_subcalls() { // The XCC precompile does internal sub-calls. We will trace an XCC call. let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let mut signer = Signer::random(); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let xcc_address = aurora_engine_precompiles::xcc::cross_contract_call::ADDRESS; runner.init_evm(); // Deploy an ERC-20 contract to act as wNEAR. It doesn't actually need to be bridged for // this test because we are not executing any scheduled promises. - let constructor = test_utils::erc20::ERC20Constructor::load(); + let constructor = ERC20Constructor::load(); let deploy_tx = constructor.deploy("wNEAR", "WNEAR", signer.use_nonce().into()); let deploy_result = runner .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); let wnear_address = { - let bytes = test_utils::unwrap_success_slice(&deploy_result); + let bytes = utils::unwrap_success_slice(&deploy_result); Address::try_from_slice(bytes).unwrap() }; - let wnear = test_utils::erc20::ERC20(constructor.0.deployed_at(wnear_address)); + let wnear = ERC20(constructor.0.deployed_at(wnear_address)); let mint_tx = wnear.mint(signer_address, u128::MAX.into(), signer.use_nonce().into()); runner .submit_transaction(&signer.secret_key, mint_tx) @@ -297,7 +298,7 @@ fn test_trace_precompiles_with_subcalls() { let key = storage::bytes_to_key(storage::KeyPrefix::Erc20Nep141Map, wnear_address.as_bytes()); outcome.diff.modify(key, b"wrap.near".to_vec()); - test_utils::standalone::storage::commit(storage, &outcome); + standalone::storage::commit(storage, &outcome); } // Setup xcc precompile in standalone runner diff --git a/engine-tests/src/tests/standalone/json_snapshot.rs b/engine-tests/src/tests/standalone/json_snapshot.rs index 95abee687..be55c8d58 100644 --- a/engine-tests/src/tests/standalone/json_snapshot.rs +++ b/engine-tests/src/tests/standalone/json_snapshot.rs @@ -1,4 +1,4 @@ -use crate::test_utils::{self, standalone}; +use crate::utils::{self, standalone}; use aurora_engine_types::storage::{self, KeyPrefix}; use aurora_engine_types::types::{Address, Wei}; use aurora_engine_types::{H160, U256}; @@ -58,8 +58,8 @@ fn test_produce_snapshot() { // add a couple more transactions that write some extra keys runner.env.block_height = snapshot.result.block_height + 1; let sk = libsecp256k1::SecretKey::parse(&[0x77; 32]).unwrap(); - let mut signer = test_utils::Signer::new(sk); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let mut signer = utils::Signer::new(sk); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let dest1 = Address::from_array([0x11; 20]); let dest2 = Address::from_array([0x22; 20]); let initial_balance = Wei::from_eth(U256::one()).unwrap(); @@ -102,7 +102,7 @@ fn test_produce_snapshot() { if (key[0..3] == [7, 6, 1]) || (key == state_key) { continue; } - println!("{}", hex::encode(&key)); + let value = aurora_engine_sdk::base64::decode(entry.value).unwrap(); assert_eq!(computed_snapshot.get(&key).unwrap(), &value); } diff --git a/engine-tests/src/tests/standalone/storage.rs b/engine-tests/src/tests/standalone/storage.rs index 993a9e9b5..5671551a8 100644 --- a/engine-tests/src/tests/standalone/storage.rs +++ b/engine-tests/src/tests/standalone/storage.rs @@ -6,16 +6,16 @@ use engine_standalone_storage::{ BlockMetadata, }; -use crate::test_utils::standalone::{mocks, storage::create_db}; -use crate::test_utils::{self, Signer}; +use crate::utils::standalone::{mocks, storage::create_db}; +use crate::utils::{self, Signer}; #[test] #[allow(clippy::too_many_lines)] fn test_replay_transaction() { let mut signer = Signer::random(); - let address = test_utils::address_from_secret_key(&signer.secret_key); + let address = utils::address_from_secret_key(&signer.secret_key); let balance = Wei::new_u64(1000); - let dest_address = test_utils::address_from_secret_key(&Signer::random().secret_key); + let dest_address = utils::address_from_secret_key(&Signer::random().secret_key); let transfer_amounts: Vec = vec![10, 13, 75, 88, 1, 9, 19, 256] .into_iter() .map(Wei::new_u64) @@ -28,11 +28,11 @@ fn test_replay_transaction() { Some(new_total) }) .collect(); - let mut runner = test_utils::standalone::StandaloneRunner::default(); + let mut runner = utils::standalone::StandaloneRunner::default(); let chain_id = Some(runner.chain_id); let create_transfer = |from: &mut Signer, to: Address, amount: Wei| { - test_utils::sign_transaction( - test_utils::transfer(to, amount, from.use_nonce().into()), + utils::sign_transaction( + utils::transfer(to, amount, from.use_nonce().into()), chain_id, &from.secret_key, ) @@ -93,7 +93,7 @@ fn test_replay_transaction() { ) .unwrap(); - test_utils::standalone::storage::commit(&mut runner.storage, &diff); + utils::standalone::storage::commit(&mut runner.storage, &diff); assert_eq!( runner.get_balance(&address), @@ -134,12 +134,12 @@ fn test_replay_transaction() { fn test_consume_transaction() { // Some util structures we will use in this test let signer = Signer::random(); - let address = test_utils::address_from_secret_key(&signer.secret_key); + let address = utils::address_from_secret_key(&signer.secret_key); let balance = Wei::new_u64(1000); let transfer_amount = Wei::new_u64(37); let nonce = signer.nonce.into(); - let dest_address = test_utils::address_from_secret_key(&Signer::random().secret_key); - let mut runner = test_utils::standalone::StandaloneRunner::default(); + let dest_address = utils::address_from_secret_key(&Signer::random().secret_key); + let mut runner = utils::standalone::StandaloneRunner::default(); runner.init_evm(); runner.mint_account(address, balance, nonce, None); @@ -149,7 +149,7 @@ fn test_consume_transaction() { assert_eq!(runner.get_nonce(&address), U256::zero()); // Try to execute a transfer transaction - let tx = test_utils::transfer(dest_address, transfer_amount, nonce); + let tx = utils::transfer(dest_address, transfer_amount, nonce); let result = runner.submit_transaction(&signer.secret_key, tx).unwrap(); assert!(result.status.is_ok()); @@ -336,12 +336,12 @@ fn test_transaction_index() { fn test_track_key() { // Set up the test let mut signer = Signer::random(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let initial_balance = Wei::new_u64(1000); let transfer_amount = Wei::new_u64(37); let dest1 = Address::from_array([0x11; 20]); let dest2 = Address::from_array([0x22; 20]); - let mut runner = test_utils::standalone::StandaloneRunner::default(); + let mut runner = utils::standalone::StandaloneRunner::default(); runner.init_evm(); runner.mint_account(signer_address, initial_balance, signer.nonce.into(), None); diff --git a/engine-tests/src/tests/standalone/sync.rs b/engine-tests/src/tests/standalone/sync.rs index be9a041c3..9371bdb57 100644 --- a/engine-tests/src/tests/standalone/sync.rs +++ b/engine-tests/src/tests/standalone/sync.rs @@ -1,12 +1,13 @@ use aurora_engine::deposit_event::TokenMessageData; use aurora_engine_modexp::AuroraModExp; use aurora_engine_sdk::env::{Env, Timestamp}; +use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize}; use aurora_engine_types::types::{Address, Balance, Fee, NEP141Wei, Wei}; use aurora_engine_types::{account_id::AccountId, H160, H256, U256}; -use borsh::{BorshDeserialize, BorshSerialize}; use engine_standalone_storage::sync; -use crate::test_utils::{self, standalone::StandaloneRunner}; +use crate::utils::solidity::erc20::{ERC20Constructor, ERC20}; +use crate::utils::{self, standalone::StandaloneRunner}; #[test] fn test_consume_block_message() { @@ -135,7 +136,7 @@ fn test_consume_deploy_message() { let (mut runner, block_message) = initialize(); let code = b"hello_world!".to_vec(); - let input = test_utils::create_deploy_transaction(code.clone(), U256::zero()).data; + let input = utils::create_deploy_transaction(code.clone(), U256::zero()).data; let transaction_message = sync::types::TransactionMessage { block_hash: block_message.hash, @@ -219,8 +220,8 @@ fn test_consume_deploy_erc20_message() { runner.env.block_height += 1; runner.env.signer_account_id = "some_account.near".parse().unwrap(); runner.env.predecessor_account_id = token; - test_utils::standalone::mocks::insert_block(&mut runner.storage, runner.env.block_height); - let block_hash = test_utils::standalone::mocks::compute_block_hash(runner.env.block_height); + utils::standalone::mocks::insert_block(&mut runner.storage, runner.env.block_height); + let block_hash = utils::standalone::mocks::compute_block_hash(runner.env.block_height); let args = aurora_engine::parameters::NEP141FtOnTransferArgs { sender_id: "mr_money_bags.near".parse().unwrap(), @@ -247,16 +248,16 @@ fn test_consume_deploy_erc20_message() { .unwrap(); // Check balance is correct - let deployed_token = test_utils::erc20::ERC20( - test_utils::erc20::ERC20Constructor::load() + let deployed_token = ERC20( + ERC20Constructor::load() .0 .deployed_at(Address::try_from_slice(&erc20_address).unwrap()), ); - let signer = test_utils::Signer::random(); + let signer = utils::Signer::random(); let tx = deployed_token.balance_of(dest_address, signer.nonce.into()); let result = runner.submit_transaction(&signer.secret_key, tx).unwrap(); assert_eq!( - U256::from_big_endian(&test_utils::unwrap_success(result)).low_u128(), + U256::from_big_endian(&utils::unwrap_success(result)).low_u128(), mint_amount ); } @@ -322,8 +323,8 @@ fn test_consume_call_message() { runner.env.block_height += 1; runner.env.signer_account_id = caller.parse().unwrap(); runner.env.predecessor_account_id = caller.parse().unwrap(); - test_utils::standalone::mocks::insert_block(&mut runner.storage, runner.env.block_height); - let block_hash = test_utils::standalone::mocks::compute_block_hash(runner.env.block_height); + utils::standalone::mocks::insert_block(&mut runner.storage, runner.env.block_height); + let block_hash = utils::standalone::mocks::compute_block_hash(runner.env.block_height); let transaction_message = sync::types::TransactionMessage { block_hash, @@ -358,23 +359,23 @@ fn test_consume_call_message() { fn test_consume_submit_message() { let (mut runner, _) = initialize(); - let mut signer = test_utils::Signer::random(); + let mut signer = utils::Signer::random(); let initial_balance = Wei::new_u64(800_000); let transfer_amount = Wei::new_u64(115_321); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let recipient_address = Address::new(H160([1u8; 20])); runner.mint_account(signer_address, initial_balance, signer.nonce.into(), None); runner.env.block_height += 1; - test_utils::standalone::mocks::insert_block(&mut runner.storage, runner.env.block_height); - let block_hash = test_utils::standalone::mocks::compute_block_hash(runner.env.block_height); - let transaction = test_utils::transfer( + utils::standalone::mocks::insert_block(&mut runner.storage, runner.env.block_height); + let block_hash = utils::standalone::mocks::compute_block_hash(runner.env.block_height); + let transaction = utils::transfer( recipient_address, transfer_amount, signer.use_nonce().into(), ); let signed_transaction = - test_utils::sign_transaction(transaction, Some(runner.chain_id), &signer.secret_key); + utils::sign_transaction(transaction, Some(runner.chain_id), &signer.secret_key); let eth_transaction = crate::prelude::transactions::EthTransactionKind::Legacy(signed_transaction); @@ -405,7 +406,7 @@ fn test_consume_submit_message() { } fn mock_proof(recipient_address: Address, deposit_amount: Wei) -> aurora_engine::proof::Proof { - let eth_custodian_address = test_utils::standalone::mocks::ETH_CUSTODIAN_ADDRESS; + let eth_custodian_address = utils::standalone::mocks::ETH_CUSTODIAN_ADDRESS; let fee = Fee::new(NEP141Wei::new(0)); let message = ["aurora", ":", recipient_address.encode().as_str()].concat(); @@ -463,7 +464,7 @@ fn simple_transfer_args( fn sample_block() -> sync::types::BlockMessage { let block_height = 101; - let block_hash = test_utils::standalone::mocks::compute_block_hash(block_height); + let block_hash = utils::standalone::mocks::compute_block_hash(block_height); sync::types::BlockMessage { height: block_height, @@ -486,7 +487,7 @@ fn initialize() -> (StandaloneRunner, sync::types::BlockMessage) { ) .unwrap(); - let env = test_utils::standalone::mocks::default_env(block_message.height); + let env = utils::standalone::mocks::default_env(block_message.height); runner.env = env; (runner, block_message) diff --git a/engine-tests/src/tests/standalone/tracing.rs b/engine-tests/src/tests/standalone/tracing.rs index 24b209731..7424d8c29 100644 --- a/engine-tests/src/tests/standalone/tracing.rs +++ b/engine-tests/src/tests/standalone/tracing.rs @@ -5,7 +5,7 @@ use engine_standalone_tracing::{sputnik, types::TransactionTrace}; use serde::Deserialize; use std::path::Path; -use crate::test_utils::{self, standalone}; +use crate::utils::{self, standalone}; /// This test replays two transactions from Ethereum mainnet (listed below) and checks we obtain /// the same gas usage and transaction trace as reported by etherscan. @@ -18,8 +18,8 @@ use crate::test_utils::{self, standalone}; #[test] fn test_evm_tracing_with_storage() { let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); + let mut signer = utils::Signer::random(); + let signer_address = utils::address_from_secret_key(&signer.secret_key); let sender_address = Address::decode("304ee8ae14eceb3a544dff53a27eb1bb1aaa471f").unwrap(); let weth_address = Address::decode("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2").unwrap(); @@ -28,13 +28,12 @@ fn test_evm_tracing_with_storage() { runner.mint_account(signer_address, Wei::zero(), signer.nonce.into(), None); // Deploy WETH contract - let weth_constructor = test_utils::weth::WethConstructor::load(); + let weth_constructor = utils::solidity::weth::WethConstructor::load(); let deploy_tx = weth_constructor.deploy(signer.use_nonce().into()); let result = runner .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); - let contract_address = - Address::try_from_slice(test_utils::unwrap_success_slice(&result)).unwrap(); + let contract_address = Address::try_from_slice(utils::unwrap_success_slice(&result)).unwrap(); // Move it over to the same address as it exists on mainnet let mut diff = engine_standalone_storage::Diff::default(); @@ -52,7 +51,7 @@ fn test_evm_tracing_with_storage() { } runner.env.block_height += 1; let block_height = runner.env.block_height; - let block_hash = test_utils::standalone::mocks::compute_block_hash(block_height); + let block_hash = standalone::mocks::compute_block_hash(block_height); let block_metadata = engine_standalone_storage::BlockMetadata { timestamp: runner.env.block_timestamp(), random_seed: runner.env.random_seed(), @@ -77,7 +76,7 @@ fn test_evm_tracing_with_storage() { diff, maybe_result: Ok(None), }; - test_utils::standalone::storage::commit(&mut runner.storage, &tx); + standalone::storage::commit(&mut runner.storage, &tx); // Replay transaction depositing some ETH to get WETH (for the first time) // tx: https://etherscan.io/tx/0x79f7f8f9b3ad98f29a3df5cbed1556397089701c3ce007c2844605849dfb0ad4 @@ -132,7 +131,7 @@ fn test_evm_tracing_with_storage() { #[test] fn test_evm_tracing() { let mut runner = standalone::StandaloneRunner::default(); - let mut signer = test_utils::Signer::random(); + let mut signer = utils::Signer::random(); // Initialize EVM runner.init_evm(); @@ -149,8 +148,7 @@ fn test_evm_tracing() { let result = runner .submit_transaction(&signer.secret_key, deploy_tx) .unwrap(); - let contract_address = - Address::try_from_slice(test_utils::unwrap_success_slice(&result)).unwrap(); + let contract_address = Address::try_from_slice(utils::unwrap_success_slice(&result)).unwrap(); // Interact with contract (and trace execution) let tx = aurora_engine_transactions::legacy::TransactionLegacy { diff --git a/engine-tests/src/tests/standard_precompiles.rs b/engine-tests/src/tests/standard_precompiles.rs index 94454ba63..d227216d7 100644 --- a/engine-tests/src/tests/standard_precompiles.rs +++ b/engine-tests/src/tests/standard_precompiles.rs @@ -1,7 +1,7 @@ use crate::prelude::Wei; -use crate::test_utils::{ +use crate::utils::{ self, - standard_precompiles::{PrecompilesConstructor, PrecompilesContract}, + solidity::standard_precompiles::{PrecompilesConstructor, PrecompilesContract}, AuroraRunner, ExecutionProfile, Signer, }; @@ -24,69 +24,69 @@ fn test_standard_precompiles() { .submit_with_signer(&mut signer, |nonce| contract.call_method("test_all", nonce)) .unwrap(); - test_utils::panic_on_fail(outcome.status); + utils::panic_on_fail(outcome.status); } #[test] fn profile_ecrecover() { let profile = precompile_execution_profile("test_ecrecover"); - test_utils::assert_gas_bound(profile.all_gas(), 6); + utils::assert_gas_bound(profile.all_gas(), 6); } #[test] fn profile_sha256() { let profile = precompile_execution_profile("test_sha256"); - test_utils::assert_gas_bound(profile.all_gas(), 5); + utils::assert_gas_bound(profile.all_gas(), 5); } #[test] fn profile_ripemd160() { let profile = precompile_execution_profile("test_ripemd160"); - test_utils::assert_gas_bound(profile.all_gas(), 5); + utils::assert_gas_bound(profile.all_gas(), 5); } #[test] fn profile_identity() { let profile = precompile_execution_profile("test_identity"); - test_utils::assert_gas_bound(profile.all_gas(), 5); + utils::assert_gas_bound(profile.all_gas(), 5); } #[test] fn profile_modexp() { let profile = precompile_execution_profile("test_modexp"); - test_utils::assert_gas_bound(profile.all_gas(), 7); + utils::assert_gas_bound(profile.all_gas(), 7); } #[test] fn profile_ecadd() { let profile = precompile_execution_profile("test_ecadd"); - test_utils::assert_gas_bound(profile.all_gas(), 5); + utils::assert_gas_bound(profile.all_gas(), 5); } #[test] fn profile_ecmul() { let profile = precompile_execution_profile("test_ecmul"); - test_utils::assert_gas_bound(profile.all_gas(), 6); + utils::assert_gas_bound(profile.all_gas(), 6); } #[test] fn profile_ecpair() { let profile = precompile_execution_profile("test_ecpair"); - test_utils::assert_gas_bound(profile.all_gas(), 102); + utils::assert_gas_bound(profile.all_gas(), 102); } #[test] fn profile_blake2f() { let profile = precompile_execution_profile("test_blake2f"); - test_utils::assert_gas_bound(profile.all_gas(), 6); + utils::assert_gas_bound(profile.all_gas(), 6); } fn initialize() -> (AuroraRunner, Signer, PrecompilesContract) { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut signer = Signer::random(); signer.nonce = INITIAL_NONCE; runner.create_address( - test_utils::address_from_secret_key(&signer.secret_key), + utils::address_from_secret_key(&signer.secret_key), INITIAL_BALANCE, INITIAL_NONCE.into(), ); diff --git a/engine-tests/src/tests/state_migration.rs b/engine-tests/src/tests/state_migration.rs deleted file mode 100644 index ca0a95e74..000000000 --- a/engine-tests/src/tests/state_migration.rs +++ /dev/null @@ -1,118 +0,0 @@ -use crate::prelude::U256; -use crate::test_utils::{self, str_to_account_id, AuroraRunner}; -use aurora_engine::fungible_token::FungibleTokenMetadata; -use aurora_engine::parameters::{InitCallArgs, NewCallArgs, NewCallArgsV2}; -use borsh::BorshSerialize; -use near_sdk_sim::{ExecutionResult, UserAccount}; -use std::fs; -use std::path::Path; - -#[test] -fn test_state_migration() { - let aurora = deploy_evm(); - - // do upgrade - let upgraded_contract_bytes = contract_bytes(); - aurora - .call("stage_upgrade", &upgraded_contract_bytes) - .assert_success(); - aurora.call("deploy_upgrade", &[]).assert_success(); - - // upgraded contract as some_new_fancy_function - let result = aurora.call("some_new_fancy_function", &[]); - result.assert_success(); - let some_numbers: [u32; 7] = result.unwrap_borsh(); - assert_eq!(some_numbers, [3, 1, 4, 1, 5, 9, 2]); -} - -#[test] -fn test_repeated_calls_to_deploy_upgrade_should_fail() { - let aurora = deploy_evm(); - - // First upgrade should succeed - let upgraded_contract_bytes = contract_bytes(); - aurora - .call("stage_upgrade", &upgraded_contract_bytes) - .assert_success(); - aurora.call("deploy_upgrade", &[]).assert_success(); - - // Second upgrade should fail - aurora.call("stage_upgrade", &upgraded_contract_bytes); - let result = aurora.call("deploy_upgrade", &[]); - assert!(!result.is_ok()); -} - -pub fn deploy_evm() -> AuroraAccount { - let aurora_runner = AuroraRunner::default(); - let main_account = near_sdk_sim::init_simulator(None); - let sim_aurora_account = format!( - "{}.{}", - aurora_runner.aurora_account_id, - main_account.account_id() - ); - let contract_account = main_account.deploy( - aurora_runner.code.code(), - sim_aurora_account.parse().unwrap(), - 5 * near_sdk_sim::STORAGE_AMOUNT, - ); - let prover_account = str_to_account_id("prover.near"); - let new_args = NewCallArgs::V2(NewCallArgsV2 { - chain_id: crate::prelude::u256_to_arr(&U256::from(aurora_runner.chain_id)), - owner_id: str_to_account_id(main_account.account_id.as_str()), - upgrade_delay_blocks: 1, - }); - main_account - .call( - contract_account.account_id.clone(), - "new", - &new_args.try_to_vec().unwrap(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - let init_args = InitCallArgs { - prover_account, - eth_custodian_address: "d045f7e19B2488924B97F9c145b5E51D0D895A65".to_string(), - metadata: FungibleTokenMetadata::default(), - }; - contract_account - .call( - contract_account.account_id.clone(), - "new_eth_connector", - &init_args.try_to_vec().unwrap(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - AuroraAccount { - user: main_account, - contract: contract_account, - } -} - -pub struct AuroraAccount { - pub user: UserAccount, - pub contract: UserAccount, -} - -impl AuroraAccount { - pub fn call(&self, method: &str, args: &[u8]) -> ExecutionResult { - self.user.call( - self.contract.account_id.clone(), - method, - args, - near_sdk_sim::DEFAULT_GAS, - 0, - ) - } -} - -fn contract_bytes() -> Vec { - let base_path = Path::new("../etc") - .join("tests") - .join("state-migration-test"); - let output_path = base_path - .join("target/wasm32-unknown-unknown/release/aurora_engine_state_migration_test.wasm"); - test_utils::rust::compile(base_path); - fs::read(output_path).unwrap() -} diff --git a/engine-tests/src/tests/eip1559.rs b/engine-tests/src/tests/transaction.rs similarity index 62% rename from engine-tests/src/tests/eip1559.rs rename to engine-tests/src/tests/transaction.rs index 8c468a468..9c8204398 100644 --- a/engine-tests/src/tests/eip1559.rs +++ b/engine-tests/src/tests/transaction.rs @@ -3,9 +3,11 @@ use crate::prelude::transactions::eip_2930::AccessTuple; use crate::prelude::transactions::EthTransactionKind; use crate::prelude::Wei; use crate::prelude::{H256, U256}; -use crate::test_utils; +use crate::utils; use aurora_engine::parameters::SubmitResult; -use borsh::BorshDeserialize; +use aurora_engine_transactions::eip_2930; +use aurora_engine_transactions::eip_2930::Transaction2930; +use aurora_engine_types::borsh::BorshDeserialize; use std::convert::TryFrom; use std::iter; @@ -27,7 +29,7 @@ fn test_eip_1559_tx_encoding_decoding() { let secret_key = example_signer().secret_key; let transaction = example_transaction(); - let signed_tx = test_utils::sign_eip_1559_transaction(transaction, &secret_key); + let signed_tx = utils::sign_eip_1559_transaction(transaction, &secret_key); let bytes = encode_tx(&signed_tx); let expected_bytes = hex::decode(EXAMPLE_TX_HEX).unwrap(); @@ -43,7 +45,7 @@ fn test_eip_1559_tx_encoding_decoding() { assert_eq!( signed_tx.sender().unwrap(), - test_utils::address_from_secret_key(&secret_key) + utils::address_from_secret_key(&secret_key) ); } @@ -51,10 +53,10 @@ fn test_eip_1559_tx_encoding_decoding() { // but modified slightly because our BASEFEE is always 0. #[test] fn test_eip_1559_example() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut signer = example_signer(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); - let contract_address = test_utils::address_from_hex(CONTRACT_ADDRESS); + let signer_address = utils::address_from_secret_key(&signer.secret_key); + let contract_address = utils::address_from_hex(CONTRACT_ADDRESS); let contract_code = hex::decode(CONTRACT_CODE).unwrap(); runner.create_address(signer_address, INITIAL_BALANCE, signer.nonce.into()); @@ -75,11 +77,11 @@ fn test_eip_1559_example() { let mut transaction = example_transaction(); transaction.chain_id = runner.chain_id; signer.use_nonce(); - let signed_tx = test_utils::sign_eip_1559_transaction(transaction, &signer.secret_key); + let signed_tx = utils::sign_eip_1559_transaction(transaction, &signer.secret_key); let sender = "relay.aurora"; let outcome = runner - .call(test_utils::SUBMIT, sender, encode_tx(&signed_tx)) + .call(utils::SUBMIT, sender, encode_tx(&signed_tx)) .unwrap(); let result = SubmitResult::try_from_slice(&outcome.return_data.as_value().unwrap()).unwrap(); assert_eq!(result.gas_used, 0xb8d2); @@ -105,17 +107,71 @@ fn test_eip_1559_example() { assert_eq!(runner.get_balance(coinbase), Wei::new_u64(0x73834)); } +// Test taken from https://github.com/ethereum/tests/blob/develop/GeneralStateTests/stExample/accessListExample.json +// TODO(#170): generally support Ethereum tests +#[test] +fn test_access_list_tx_encoding_decoding() { + let secret_key = libsecp256k1::SecretKey::parse_slice( + &hex::decode("45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8").unwrap(), + ) + .unwrap(); + let transaction = Transaction2930 { + chain_id: 1, + nonce: U256::zero(), + gas_price: U256::from(0x0a), + gas_limit: U256::from(0x061a80), + to: Some(utils::address_from_hex( + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + )), + value: Wei::new_u64(0x0186a0), + data: vec![0], + access_list: vec![ + AccessTuple { + address: utils::address_from_hex("0x095e7baea6a6c7c4c2dfeb977efac326af552d87") + .raw(), + storage_keys: vec![H256::zero(), one()], + }, + AccessTuple { + address: utils::address_from_hex("0x195e7baea6a6c7c4c2dfeb977efac326af552d87") + .raw(), + storage_keys: vec![H256::zero()], + }, + ], + }; + + let signed_tx = utils::sign_access_list_transaction(transaction, &secret_key); + let bytes: Vec = iter::once(eip_2930::TYPE_BYTE) + .chain(rlp::encode(&signed_tx).into_iter()) + .collect(); + let expected_bytes = hex::decode("01f8f901800a83061a8094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a000f893f85994095e7baea6a6c7c4c2dfeb977efac326af552d87f842a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001f794195e7baea6a6c7c4c2dfeb977efac326af552d87e1a0000000000000000000000000000000000000000000000000000000000000000080a011c97e0bb8a356fe4f49b37863d059c6fe8cd3214a6ac06a8387a2f6f0b75f60a0212368a1097da30806edfd13d9c35662e1baee939235eb25de867980bd0eda26").unwrap(); + + assert_eq!(bytes, expected_bytes); + + let decoded_tx = match EthTransactionKind::try_from(expected_bytes.as_slice()) { + Ok(EthTransactionKind::Eip2930(tx)) => tx, + Ok(_) => panic!("Unexpected transaction type"), + Err(e) => panic!("Transaction parsing failed: {e:?}"), + }; + + assert_eq!(signed_tx, decoded_tx); + + assert_eq!( + signed_tx.sender().unwrap(), + utils::address_from_secret_key(&secret_key) + ); +} + fn encode_tx(signed_tx: &SignedTransaction1559) -> Vec { iter::once(eip_1559::TYPE_BYTE) .chain(rlp::encode(signed_tx).into_iter()) .collect() } -fn example_signer() -> test_utils::Signer { +fn example_signer() -> utils::Signer { let secret_key = libsecp256k1::SecretKey::parse_slice(&hex::decode(SECRET_KEY).unwrap()).unwrap(); - test_utils::Signer { + utils::Signer { nonce: INITIAL_NONCE, secret_key, } @@ -128,11 +184,11 @@ fn example_transaction() -> Transaction1559 { gas_limit: U256::from(0x3d0900), max_fee_per_gas: U256::from(0x07d0), max_priority_fee_per_gas: U256::from(0x0a), - to: Some(test_utils::address_from_hex(CONTRACT_ADDRESS)), + to: Some(utils::address_from_hex(CONTRACT_ADDRESS)), value: Wei::zero(), data: vec![0], access_list: vec![AccessTuple { - address: test_utils::address_from_hex(CONTRACT_ADDRESS).raw(), + address: utils::address_from_hex(CONTRACT_ADDRESS).raw(), storage_keys: vec![H256::zero(), one()], }], } diff --git a/engine-tests/src/tests/uniswap.rs b/engine-tests/src/tests/uniswap.rs index 4c28b7403..71b9958d9 100644 --- a/engine-tests/src/tests/uniswap.rs +++ b/engine-tests/src/tests/uniswap.rs @@ -1,8 +1,8 @@ use crate::prelude::{Address, U256}; -use crate::test_utils::{ +use crate::utils::{ self, - erc20::{ERC20Constructor, ERC20}, - uniswap::{ + solidity::erc20::{ERC20Constructor, ERC20}, + solidity::uniswap::{ ExactInputParams, ExactOutputSingleParams, Factory, FactoryConstructor, MintParams, Pool, PositionManager, PositionManagerConstructor, SwapRouter, SwapRouterConstructor, }, @@ -49,7 +49,7 @@ fn test_uniswap_exact_output() { let (_result, profile) = context.add_equal_liquidity(LIQUIDITY_AMOUNT.into(), &token_a, &token_b); - test_utils::assert_gas_bound(profile.all_gas(), 32); + utils::assert_gas_bound(profile.all_gas(), 32); let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas(); assert!( (40..=50).contains(&wasm_fraction), @@ -58,7 +58,7 @@ fn test_uniswap_exact_output() { let (_amount_in, profile) = context.exact_output_single(&token_a, &token_b, OUTPUT_AMOUNT.into()); - test_utils::assert_gas_bound(profile.all_gas(), 17); + utils::assert_gas_bound(profile.all_gas(), 17); let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas(); assert!( (45..=55).contains(&wasm_fraction), @@ -85,10 +85,10 @@ pub struct UniswapTestContext { impl UniswapTestContext { pub fn new(name: &str) -> Self { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); let mut rng = rand::rngs::StdRng::seed_from_u64(414_243); let source_account = SecretKey::random(&mut rng); - let source_address = test_utils::address_from_secret_key(&source_account); + let source_address = utils::address_from_secret_key(&source_account); runner.create_address( source_address, Wei::new_u64(INITIAL_BALANCE), @@ -186,7 +186,7 @@ impl UniswapTestContext { .unwrap(); assert!(result.status.is_ok(), "Failed to create pool"); - let address = Address::try_from_slice(&test_utils::unwrap_success(result)[12..]).unwrap(); + let address = Address::try_from_slice(&utils::unwrap_success(result)[12..]).unwrap(); let pool = Pool::from_address(address); // 2^96 corresponds to a price ratio of 1 @@ -215,7 +215,7 @@ impl UniswapTestContext { amount1_desired: amount, amount0_min: U256::one(), amount1_min: U256::one(), - recipient: test_utils::address_from_secret_key(&self.signer.secret_key), + recipient: utils::address_from_secret_key(&self.signer.secret_key), deadline: U256::MAX, // no deadline } } @@ -240,7 +240,7 @@ impl UniswapTestContext { let result = { let mut values = [U256::zero(); 4]; - let result_bytes = test_utils::unwrap_success(result); + let result_bytes = utils::unwrap_success(result); for (i, item) in values.iter_mut().enumerate() { let lower = i * 32; let upper = (i + 1) * 32; @@ -296,7 +296,7 @@ impl UniswapTestContext { assert!(result.status.is_ok(), "Swap failed"); let evm_gas = result.gas_used; - let amount_out = U256::from_big_endian(&test_utils::unwrap_success(result)); + let amount_out = U256::from_big_endian(&utils::unwrap_success(result)); (amount_out, evm_gas, profile) } @@ -337,7 +337,7 @@ impl UniswapTestContext { .unwrap(); assert!(result.status.is_ok(), "Swap failed"); - let amount_in = U256::from_big_endian(&test_utils::unwrap_success(result)); + let amount_in = U256::from_big_endian(&utils::unwrap_success(result)); assert!(amount_in >= amount_out); (amount_in, profile) @@ -379,7 +379,7 @@ impl UniswapTestContext { let nonce = signer.use_nonce(); let mint_tx = contract.mint( - test_utils::address_from_secret_key(&signer.secret_key), + utils::address_from_secret_key(&signer.secret_key), mint_amount, nonce.into(), ); diff --git a/engine-tests/src/tests/upgrade.rs b/engine-tests/src/tests/upgrade.rs new file mode 100644 index 000000000..3930b363f --- /dev/null +++ b/engine-tests/src/tests/upgrade.rs @@ -0,0 +1,65 @@ +use std::{fs, path::Path}; + +use crate::utils::workspace::deploy_engine; + +#[tokio::test] +async fn test_code_upgrade() { + let aurora = deploy_engine().await; + // do upgrade + let result = aurora + .stage_upgrade(contract_bytes()) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); + + let result = aurora.deploy_upgrade().max_gas().transact().await.unwrap(); + assert!(result.is_success()); + + // call a new method + let result = aurora + .as_raw_contract() + .view("some_new_fancy_function") + .await + .unwrap(); + + let output: [u32; 7] = result.borsh().unwrap(); + assert_eq!(output, [3, 1, 4, 1, 5, 9, 2]); +} + +// TODO: Should be reworked with `upgrade_delay_blocks` more then one to check that +// we get the TOO EARLY error. +#[tokio::test] +async fn test_repeated_calls_to_upgrade_should_fail() { + let aurora = deploy_engine().await; + // First upgrade should succeed + let result = aurora + .stage_upgrade(contract_bytes()) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); + + let result = aurora.deploy_upgrade().max_gas().transact().await.unwrap(); + assert!(result.is_success()); + + // Second upgrade should fail since deployed code doesn't have method `stage_upgrade`. + let result = aurora + .stage_upgrade(contract_bytes()) + .max_gas() + .transact() + .await; + assert!(result.is_err()); +} + +fn contract_bytes() -> Vec { + let base_path = Path::new("../etc") + .join("tests") + .join("state-migration-test"); + let output_path = base_path + .join("target/wasm32-unknown-unknown/release/aurora_engine_state_migration_test.wasm"); + crate::utils::rust::compile(base_path); + fs::read(output_path).unwrap() +} diff --git a/engine-tests/src/tests/xcc.rs b/engine-tests/src/tests/xcc.rs index 858fe73db..382312179 100644 --- a/engine-tests/src/tests/xcc.rs +++ b/engine-tests/src/tests/xcc.rs @@ -1,36 +1,32 @@ -use crate::test_utils::erc20::{ERC20Constructor, ERC20}; -use crate::test_utils::{self, AuroraRunner, ORIGIN}; -use crate::tests::erc20_connector::sim_tests; -use crate::tests::state_migration::{deploy_evm, AuroraAccount}; -use aurora_engine_precompiles::xcc::{self, costs, cross_contract_call}; +use crate::utils::solidity::erc20::{ERC20Constructor, ERC20}; +use crate::utils::{self, AuroraRunner, ORIGIN}; +use aurora_engine_precompiles::xcc::{costs, cross_contract_call}; use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::account_id::AccountId; +use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize}; use aurora_engine_types::parameters::{ CrossContractCallArgs, NearPromise, PromiseArgs, PromiseCreateArgs, PromiseWithCallbackArgs, SimpleNearPromise, }; use aurora_engine_types::types::{Address, EthGas, NearGas, Wei, Yocto}; use aurora_engine_types::U256; -use borsh::{BorshDeserialize, BorshSerialize}; use near_primitives::transaction::Action; use near_primitives_core::contract::ContractCode; -use near_sdk_sim::UserAccount; -use serde_json::json; use std::fs; use std::path::Path; -const WNEAR_AMOUNT: u128 = 10 * near_sdk_sim::STORAGE_AMOUNT; -const ONE_NEAR: u128 = 1_000_000_000_000_000_000_000_000; +const WNEAR_AMOUNT: u128 = 10 * 50_000_000_000_000_000_000_000_000; +const STORAGE_AMOUNT: i128 = 50_000_000_000_000_000_000_000_000; #[test] #[allow(clippy::too_many_lines)] fn test_xcc_eth_gas_cost() { - let mut runner = test_utils::deploy_evm(); + let mut runner = utils::deploy_runner(); runner.standalone_runner = None; let xcc_wasm_bytes = contract_bytes(); let _res = runner.call("factory_update", ORIGIN, xcc_wasm_bytes); - let mut signer = test_utils::Signer::random(); - let mut baseline_signer = test_utils::Signer::random(); + let mut signer = utils::Signer::random(); + let mut baseline_signer = utils::Signer::random(); runner.context.block_height = aurora_engine::engine::ZERO_ADDRESS_FIX_HEIGHT + 1; // Need to use for engine's deployment! let wnear_erc20 = deploy_erc20(&mut runner, &mut signer); @@ -42,7 +38,7 @@ fn test_xcc_eth_gas_cost() { ); approve_erc20( &wnear_erc20, - test_utils::address_from_secret_key(&baseline_signer.secret_key), + utils::address_from_secret_key(&baseline_signer.secret_key), &mut runner, &mut signer, ); @@ -58,9 +54,9 @@ fn test_xcc_eth_gas_cost() { let (baseline_result, baseline) = runner .submit_with_signer_profiled(&mut baseline_signer, |nonce| { wnear_erc20.transfer_from( - test_utils::address_from_secret_key(&signer.secret_key), + utils::address_from_secret_key(&signer.secret_key), Address::from_array([1u8; 20]), - U256::from(near_sdk_sim::STORAGE_AMOUNT), + U256::from(STORAGE_AMOUNT), nonce, ) }) @@ -116,7 +112,7 @@ fn test_xcc_eth_gas_cost() { let xcc_cost_per_byte = xcc_cost_per_byte / costs::CROSS_CONTRACT_CALL_NEAR_GAS; assert!( - test_utils::within_x_percent( + utils::within_x_percent( 5, xcc_base_cost.as_u64(), costs::CROSS_CONTRACT_CALL_BASE.as_u64() @@ -127,7 +123,7 @@ fn test_xcc_eth_gas_cost() { ); assert!( - test_utils::within_x_percent( + utils::within_x_percent( 5, xcc_cost_per_byte, costs::CROSS_CONTRACT_CALL_BYTE.as_u64() @@ -146,226 +142,19 @@ fn test_xcc_eth_gas_cost() { + costs::ROUTER_EXEC_BASE.as_u64() + costs::ROUTER_EXEC_PER_CALLBACK.as_u64(); assert!( - test_utils::within_x_percent(20, evm1, total_gas1 / costs::CROSS_CONTRACT_CALL_NEAR_GAS), + utils::within_x_percent(20, evm1, total_gas1 / costs::CROSS_CONTRACT_CALL_NEAR_GAS), "Incorrect EVM gas used. Expected: {} Actual: {}", evm1, total_gas1 / costs::CROSS_CONTRACT_CALL_NEAR_GAS ); assert!( - test_utils::within_x_percent(20, evm2, total_gas2 / costs::CROSS_CONTRACT_CALL_NEAR_GAS), + utils::within_x_percent(20, evm2, total_gas2 / costs::CROSS_CONTRACT_CALL_NEAR_GAS), "Incorrect EVM gas used. Expected: {} Actual: {}", evm2, total_gas2 / costs::CROSS_CONTRACT_CALL_NEAR_GAS ); } -#[test] -fn test_xcc_external_fund() { - // In this test we intentionally do not bridge wNEAR into the Engine. - // The purpose of the `fund_xcc_sub_account` functionality is to allow using - // the XCC feature in an Engine instance where there is no bridged wNEAR. - - // Set up Engine contract - let aurora = deploy_evm(); - let chain_id = AuroraRunner::default().chain_id; - let mut signer = test_utils::Signer::new(libsecp256k1::SecretKey::parse(&[0xab; 32]).unwrap()); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); - let xcc_wasm_bytes = contract_bytes(); - aurora - .user - .call( - aurora.contract.account_id(), - "factory_update", - &xcc_wasm_bytes, - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - let wnear_account = deploy_wnear(&aurora); - - // Fund XCC sub-account - let fund_amount = 5 * ONE_NEAR; - let fund_args = aurora_engine::xcc::FundXccArgs { - target: signer_address, - wnear_account_id: Some(wnear_account.account_id.as_str().parse().unwrap()), - }; - aurora - .user - .call( - aurora.contract.account_id(), - "fund_xcc_sub_account", - &fund_args.try_to_vec().unwrap(), - near_sdk_sim::DEFAULT_GAS, - fund_amount, - ) - .assert_success(); - - let sub_account_id = format!( - "{}.{}", - signer_address.encode(), - aurora.contract.account_id.as_str() - ); - let sub_account = aurora - .user - .borrow_runtime() - .view_account(&sub_account_id) - .unwrap(); - assert_eq!((fund_amount - sub_account.amount()) / ONE_NEAR, 0); - - // Do an XCC call. This XCC call is to the Aurora Engine itself to deploy an EVM contract, - // but that is just for this test. The call could be to any contract to do any action. - let expected_code = hex::decode("deadbeef").unwrap(); - let deploy_code = - test_utils::create_deploy_transaction(expected_code.clone(), U256::zero()).data; - let promise = PromiseCreateArgs { - target_account_id: aurora.contract.account_id.as_str().parse().unwrap(), - method: "deploy_code".into(), - args: deploy_code, - attached_balance: Yocto::new(0), - attached_gas: NearGas::new(10_000_000_000_000), - }; - let xcc_args = CrossContractCallArgs::Eager(PromiseArgs::Create(promise)); - let _result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id); - - // This is known because we are using a fixed private key for the signer - let deployed_address = Address::decode("bda6e7f87c816d25718c38b1c753e280f9455350").unwrap(); - let code = match aurora - .call("get_code", deployed_address.as_bytes()) - .status() - { - near_sdk_sim::transaction::ExecutionStatus::SuccessValue(bytes) => bytes, - other => panic!("Unexpected status {other:?}"), - }; - - assert_eq!( - code, expected_code, - "Failed to properly deploy EVM code via XCC" - ); -} - -#[test] -fn test_xcc_precompile_eager() { - test_xcc_precompile_common(false); -} - -#[test] -fn test_xcc_precompile_scheduled() { - test_xcc_precompile_common(true); -} - -/// This test uses the XCC feature where the promise has many nested callbacks. -/// The contract it uses is one which computes Fibonacci numbers in an inefficient way. -/// The contract has two functions: `seed` and `accumulate`. -/// The `seed` function always returns `{"a": "0", "b": "1"}`. -/// The `accumulate` function performs one step of the Fibonacci recursion relation using -/// a promise result (i.e. result from prior call) as input. -/// Therefore, we can compute Fibonacci numbers by creating a long chain of callbacks. -/// For example, to compute the 6th number: -/// `seed.then(accumulate).then(accumulate).then(accumulate).then(accumulate).then(accumulate)`. -#[test] -fn test_xcc_multiple_callbacks() { - let XccTestContext { - aurora, - mut signer, - signer_address, - chain_id, - .. - } = init_xcc(); - - // 1. Deploy Fibonacci contract - let fib_account_id = deploy_fibonacci(&aurora); - - // 2. Create XCC account, schedule Fibonacci call - let n = 6; - let promise = make_fib_promise(n, &fib_account_id); - let xcc_args = CrossContractCallArgs::Delayed(PromiseArgs::Recursive(promise)); - let _result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id); - - // 3. Make Fibonacci call - let router_account = format!( - "{}.{}", - hex::encode(signer_address.as_bytes()), - aurora.contract.account_id.as_str() - ); - let result = aurora.user.call( - router_account.parse().unwrap(), - "execute_scheduled", - b"{\"nonce\": \"0\"}", - near_sdk_sim::DEFAULT_GAS, - 0, - ); - result.assert_success(); - - // 4. Check the result is correct - let output = result.unwrap_json_value(); - check_fib_result(&output, n); -} - -/// This test is similar to `test_xcc_multiple_callbacks`, but instead of computing -/// Fibonacci numbers through repeated callbacks, it uses the `And` promise combinator. -#[test] -fn test_xcc_and_combinator() { - let XccTestContext { - aurora, - mut signer, - signer_address, - chain_id, - .. - } = init_xcc(); - - // 1. Deploy Fibonacci contract - let fib_account_id = deploy_fibonacci(&aurora); - - // 2. Create XCC account, schedule Fibonacci call - let n = 6; - let promise = NearPromise::Then { - base: Box::new(NearPromise::And(vec![ - NearPromise::Simple(SimpleNearPromise::Create(PromiseCreateArgs { - target_account_id: fib_account_id.clone(), - method: "fib".into(), - args: format!(r#"{{"n": {}}}"#, n - 1).into_bytes(), - attached_balance: Yocto::new(0), - attached_gas: NearGas::new(10_000_000_000_000_u64 * n), - })), - NearPromise::Simple(SimpleNearPromise::Create(PromiseCreateArgs { - target_account_id: fib_account_id.clone(), - method: "fib".into(), - args: format!(r#"{{"n": {}}}"#, n - 2).into_bytes(), - attached_balance: Yocto::new(0), - attached_gas: NearGas::new(10_000_000_000_000_u64 * n), - })), - ])), - callback: SimpleNearPromise::Create(PromiseCreateArgs { - target_account_id: fib_account_id, - method: "sum".into(), - args: Vec::new(), - attached_balance: Yocto::new(0), - attached_gas: NearGas::new(5_000_000_000_000), - }), - }; - let xcc_args = CrossContractCallArgs::Delayed(PromiseArgs::Recursive(promise)); - let _result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id); - - // 3. Make Fibonacci call - let router_account = format!( - "{}.{}", - hex::encode(signer_address.as_bytes()), - aurora.contract.account_id.as_str() - ); - let result = aurora.user.call( - router_account.parse().unwrap(), - "execute_scheduled", - b"{\"nonce\": \"0\"}", - near_sdk_sim::DEFAULT_GAS, - 0, - ); - result.assert_success(); - - // 4. Check the result is correct - let output = result.unwrap_json_value(); - check_fib_result(&output, usize::try_from(n).unwrap()); -} - fn check_fib_result(output: &serde_json::Value, n: usize) { let fib_numbers: [u8; 8] = [0, 1, 1, 2, 3, 5, 8, 13]; let get_number = |field_name: &str| -> u8 { @@ -385,284 +174,6 @@ fn check_fib_result(output: &serde_json::Value, n: usize) { assert_eq!(b, fib_numbers[n + 1]); } -#[allow(clippy::too_many_lines)] -fn test_xcc_precompile_common(is_scheduled: bool) { - let XccTestContext { - aurora, - mut signer, - signer_address, - chain_id, - wnear_account, - } = init_xcc(); - - let router_account = format!( - "{}.{}", - hex::encode(signer_address.as_bytes()), - aurora.contract.account_id.as_str() - ); - - // 1. Deploy NEP-141 token. - let ft_owner = aurora.user.create_user( - "ft_owner.root".parse().unwrap(), - near_sdk_sim::STORAGE_AMOUNT, - ); - let nep_141_supply = 500; - let nep_141_token = sim_tests::deploy_nep_141( - "test_token.root", - ft_owner.account_id.as_ref(), - nep_141_supply, - &aurora, - ); - - // 2. Register EVM router contract - let args = serde_json::json!({ - "account_id": router_account, - }) - .to_string(); - aurora - .user - .call( - nep_141_token.account_id(), - "storage_deposit", - args.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - near_sdk_sim::STORAGE_AMOUNT, - ) - .assert_success(); - - // 3. Give router some tokens - let transfer_amount: u128 = 199; - let args = json!({ - "receiver_id": router_account, - "amount": format!("{transfer_amount}"), - }) - .to_string(); - ft_owner - .call( - nep_141_token.account_id(), - "ft_transfer", - args.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - 1, - ) - .assert_success(); - assert_eq!( - sim_tests::nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141_token, &aurora), - nep_141_supply - transfer_amount - ); - - // 4. Use xcc precompile to send those tokens back - let args = json!({ - "receiver_id": ft_owner.account_id.as_str(), - "amount": format!("{transfer_amount}"), - }) - .to_string(); - let promise = PromiseCreateArgs { - target_account_id: nep_141_token.account_id.as_str().parse().unwrap(), - method: "ft_transfer".into(), - args: args.into_bytes(), - attached_balance: Yocto::new(1), - attached_gas: NearGas::new(100_000_000_000_000), - }; - let callback = PromiseCreateArgs { - target_account_id: nep_141_token.account_id.as_str().parse().unwrap(), - method: "ft_balance_of".into(), - args: format!("{{\"account_id\":\"{router_account}\"}}").into_bytes(), - attached_balance: Yocto::new(0), - attached_gas: NearGas::new(2_000_000_000_000), - }; - let promise_args = PromiseArgs::Callback(PromiseWithCallbackArgs { - base: promise, - callback, - }); - let xcc_args = if is_scheduled { - CrossContractCallArgs::Delayed(promise_args) - } else { - CrossContractCallArgs::Eager(promise_args) - }; - let engine_balance_before_xcc = get_engine_near_balance(&aurora); - let _result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id); - - print_outcomes(&aurora); - let engine_balance_after_xcc = get_engine_near_balance(&aurora); - assert!( - // engine loses less than 0.01 NEAR - engine_balance_after_xcc.max(engine_balance_before_xcc) - - engine_balance_after_xcc.min(engine_balance_before_xcc) - < 10_000_000_000_000_000_000_000, - "Engine lost too much NEAR funding xcc: Before={engine_balance_before_xcc} After={engine_balance_after_xcc}", - ); - let router_balance = aurora - .user - .borrow_runtime() - .view_account(&router_account) - .unwrap() - .amount(); - assert!( - // router loses less than 0.01 NEAR from its allocated funds - xcc::state::STORAGE_AMOUNT.as_u128() - router_balance < 10_000_000_000_000_000_000_000, - "Router lost too much NEAR: Balance={router_balance}", - ); - // Router has no wNEAR balance because it all was unwrapped to actual NEAR - assert_eq!( - sim_tests::nep_141_balance_of(&router_account, &wnear_account, &aurora), - 0, - ); - - if is_scheduled { - // The promise was only scheduled, not executed immediately. So the FT balance has not changed yet. - assert_eq!( - sim_tests::nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141_token, &aurora), - nep_141_supply - transfer_amount - ); - - // Now we execute the scheduled promise - aurora - .user - .call( - router_account.parse().unwrap(), - "execute_scheduled", - b"{\"nonce\": \"0\"}", - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - } - - assert_eq!( - sim_tests::nep_141_balance_of(ft_owner.account_id.as_str(), &nep_141_token, &aurora), - nep_141_supply - ); -} - -/// Deploys the EVM, sets xcc router code, deploys wnear contract, bridges wnear into EVM, and calls `factory_set_wnear_address` -fn init_xcc() -> XccTestContext { - let aurora = deploy_evm(); - let chain_id = AuroraRunner::default().chain_id; - let xcc_wasm_bytes = contract_bytes(); - aurora - .user - .call( - aurora.contract.account_id(), - "factory_update", - &xcc_wasm_bytes, - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - - let mut signer = test_utils::Signer::random(); - let signer_address = test_utils::address_from_secret_key(&signer.secret_key); - - // Setup wNEAR contract and bridge it to Aurora - let wnear_account = deploy_wnear(&aurora); - let wnear_erc20 = sim_tests::deploy_erc20_from_nep_141(&wnear_account, &aurora); - sim_tests::transfer_nep_141_to_erc_20( - &wnear_account, - &wnear_erc20, - &aurora.user, - signer_address, - WNEAR_AMOUNT, - &aurora, - ); - aurora - .user - .call( - aurora.contract.account_id(), - "factory_set_wnear_address", - wnear_erc20.0.address.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - let approve_tx = wnear_erc20.approve( - cross_contract_call::ADDRESS, - WNEAR_AMOUNT.into(), - signer.use_nonce().into(), - ); - let signed_transaction = - test_utils::sign_transaction(approve_tx, Some(chain_id), &signer.secret_key); - aurora - .user - .call( - aurora.contract.account_id(), - "submit", - &rlp::encode(&signed_transaction), - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - - XccTestContext { - aurora, - signer, - signer_address, - chain_id, - wnear_account, - } -} - -struct XccTestContext { - pub aurora: AuroraAccount, - pub signer: test_utils::Signer, - pub signer_address: Address, - pub chain_id: u64, - pub wnear_account: UserAccount, -} - -fn submit_xcc_transaction( - xcc_args: &CrossContractCallArgs, - aurora: &AuroraAccount, - signer: &mut test_utils::Signer, - chain_id: u64, -) -> near_sdk_sim::ExecutionResult { - let transaction = TransactionLegacy { - nonce: signer.use_nonce().into(), - gas_price: 0u64.into(), - gas_limit: u64::MAX.into(), - to: Some(cross_contract_call::ADDRESS), - value: Wei::zero(), - data: xcc_args.try_to_vec().unwrap(), - }; - let signed_transaction = - test_utils::sign_transaction(transaction, Some(chain_id), &signer.secret_key); - let result = aurora.user.call( - aurora.contract.account_id(), - "submit", - &rlp::encode(&signed_transaction), - near_sdk_sim::DEFAULT_GAS, - 0, - ); - result.assert_success(); - let submit_result = match result.status() { - near_sdk_sim::transaction::ExecutionStatus::SuccessValue(bytes) => { - aurora_engine::parameters::SubmitResult::try_from_slice(&bytes).unwrap() - } - other => panic!("Unexpected status {other:?}"), - }; - assert!( - submit_result.status.is_ok(), - "Unexpected result: {submit_result:?}", - ); - result -} - -fn get_engine_near_balance(aurora: &AuroraAccount) -> u128 { - aurora - .user - .borrow_runtime() - .view_account(aurora.contract.account_id.as_str()) - .unwrap() - .amount() -} - -fn print_outcomes(aurora: &AuroraAccount) { - let rt = aurora.user.borrow_runtime(); - for id in &rt.last_outcomes { - println!("{:?}=={:?}\n\n", id, rt.outcome(id).unwrap()); - } -} - #[test] fn test_xcc_schedule_gas() { let mut router = deploy_router(); @@ -756,23 +267,6 @@ fn test_xcc_exec_gas() { } } -fn deploy_fibonacci(aurora: &AuroraAccount) -> AccountId { - let fib_contract_bytes = { - let base_path = Path::new("..").join("etc").join("tests").join("fibonacci"); - let output_path = - base_path.join("target/wasm32-unknown-unknown/release/fibonacci_on_near.wasm"); - test_utils::rust::compile(base_path); - fs::read(output_path).unwrap() - }; - let fib_account_id = format!("fib.{}", aurora.user.account_id.as_str()); - let _fib_account = aurora.user.deploy( - &fib_contract_bytes, - fib_account_id.parse().unwrap(), - near_sdk_sim::STORAGE_AMOUNT, - ); - fib_account_id.parse().unwrap() -} - fn deploy_router() -> AuroraRunner { let mut router = AuroraRunner { code: ContractCode::new(contract_bytes(), None), @@ -791,75 +285,7 @@ fn deploy_router() -> AuroraRunner { router } -fn deploy_wnear(aurora: &AuroraAccount) -> UserAccount { - let contract_bytes = std::fs::read("src/tests/res/w_near.wasm").unwrap(); - - let account_id = format!("wrap.{}", aurora.user.account_id.as_str()); - let contract_account = aurora.user.deploy( - &contract_bytes, - account_id.parse().unwrap(), - 5 * near_sdk_sim::STORAGE_AMOUNT, - ); - - aurora - .user - .call( - contract_account.account_id(), - "new", - &[], - near_sdk_sim::DEFAULT_GAS, - 0, - ) - .assert_success(); - - // Need to register Aurora contract so that it can receive tokens - let args = json!({ - "account_id": &aurora.contract.account_id, - }) - .to_string(); - aurora - .user - .call( - contract_account.account_id(), - "storage_deposit", - args.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - near_sdk_sim::STORAGE_AMOUNT, - ) - .assert_success(); - - // Need to also register root account - let args = json!({ - "account_id": &aurora.user.account_id, - }) - .to_string(); - aurora - .user - .call( - contract_account.account_id(), - "storage_deposit", - args.as_bytes(), - near_sdk_sim::DEFAULT_GAS, - near_sdk_sim::STORAGE_AMOUNT, - ) - .assert_success(); - - // Mint some wNEAR for the root account to use - aurora - .user - .call( - contract_account.account_id(), - "near_deposit", - &[], - near_sdk_sim::DEFAULT_GAS, - WNEAR_AMOUNT, - ) - .assert_success(); - - contract_account -} - -fn deploy_erc20(runner: &mut AuroraRunner, signer: &mut test_utils::Signer) -> ERC20 { +fn deploy_erc20(runner: &mut AuroraRunner, signer: &mut utils::Signer) -> ERC20 { let engine_account = runner.aurora_account_id.clone(); let args = aurora_engine::parameters::DeployErc20TokenArgs { nep141: "wrap.near".parse().unwrap(), @@ -879,7 +305,7 @@ fn deploy_erc20(runner: &mut AuroraRunner, signer: &mut test_utils::Signer) -> E }; let contract = ERC20(ERC20Constructor::load().0.deployed_at(address)); - let dest_address = test_utils::address_from_secret_key(&signer.secret_key); + let dest_address = utils::address_from_secret_key(&signer.secret_key); let call_args = aurora_engine::parameters::CallArgs::V1(aurora_engine::parameters::FunctionCallArgsV1 { contract: address, @@ -897,7 +323,7 @@ fn approve_erc20( token: &ERC20, spender: Address, runner: &mut AuroraRunner, - signer: &mut test_utils::Signer, + signer: &mut utils::Signer, ) { let approve_result = runner .submit_with_signer(signer, |nonce| { @@ -910,7 +336,7 @@ fn approve_erc20( pub fn contract_bytes() -> Vec { let base_path = Path::new("../etc").join("xcc-router"); let output_path = base_path.join("target/wasm32-unknown-unknown/release/xcc_router.wasm"); - test_utils::rust::compile(base_path); + utils::rust::compile(base_path); fs::read(output_path).unwrap() } @@ -938,3 +364,528 @@ fn make_fib_promise(n: usize, account_id: &AccountId) -> NearPromise { } } } + +mod workspace { + use crate::tests::xcc::{check_fib_result, WNEAR_AMOUNT}; + use crate::utils; + use crate::utils::workspace::{ + create_sub_account, deploy_engine, deploy_erc20_from_nep_141, deploy_nep_141, + nep_141_balance_of, transfer_nep_141_to_erc_20, + }; + use aurora_engine_precompiles::xcc::cross_contract_call; + use aurora_engine_transactions::legacy::TransactionLegacy; + use aurora_engine_types::account_id::AccountId; + use aurora_engine_types::borsh::BorshSerialize; + use aurora_engine_types::parameters::engine::TransactionStatus; + use aurora_engine_types::parameters::{ + CrossContractCallArgs, NearPromise, PromiseArgs, PromiseCreateArgs, + PromiseWithCallbackArgs, SimpleNearPromise, + }; + use aurora_engine_types::types::{Address, NearGas, Wei, Yocto}; + use aurora_engine_types::U256; + use aurora_engine_workspace::{parse_near, EngineContract, RawContract}; + use serde_json::json; + use std::path::Path; + + const STORAGE_AMOUNT: u128 = 50_000_000_000_000_000_000_000_000; + const ONE_NEAR: u128 = 10u128.pow(24); + + #[tokio::test] + async fn test_xcc_external_fund() { + // In this test we intentionally do not bridge wNEAR into the Engine. + // The purpose of the `fund_xcc_sub_account` functionality is to allow using + // the XCC feature in an Engine instance where there is no bridged wNEAR. + + // Set up Engine contract + let aurora = deploy_engine().await; + let chain_id = aurora.get_chain_id().await.unwrap().result.as_u64(); + let mut signer = utils::Signer::new(libsecp256k1::SecretKey::parse(&[0xab; 32]).unwrap()); + let signer_address = utils::address_from_secret_key(&signer.secret_key); + let xcc_wasm_bytes = super::contract_bytes(); + + let result = aurora + .factory_update(xcc_wasm_bytes) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); + + let wnear_account = deploy_wnear(&aurora).await.unwrap(); + + // Fund XCC sub-account + let fund_amount = parse_near!("5 N"); + let result = aurora + .fund_xcc_sub_account( + signer_address, + Some(wnear_account.id().as_ref().parse().unwrap()), + ) + .max_gas() + .deposit(fund_amount) + .transact() + .await + .unwrap(); + assert!(result.is_success()); + + let sub_account_id = format!("{}.{}", signer_address.encode(), aurora.id().as_ref()); + let sub_account_balance = aurora + .node + .get_balance(&sub_account_id.parse().unwrap()) + .await + .unwrap(); + assert_eq!((fund_amount - sub_account_balance) / ONE_NEAR, 0); + + // Do an XCC call. This XCC call is to the Aurora Engine itself to deploy an EVM contract, + // but that is just for this test. The call could be to any contract to do any action. + let expected_code = hex::decode("deadbeef").unwrap(); + let deploy_code = + utils::create_deploy_transaction(expected_code.clone(), U256::zero()).data; + let promise = PromiseCreateArgs { + target_account_id: aurora.id().as_ref().parse().unwrap(), + method: "deploy_code".into(), + args: deploy_code, + attached_balance: Yocto::new(0), + attached_gas: NearGas::new(10_000_000_000_000), + }; + let xcc_args = CrossContractCallArgs::Eager(PromiseArgs::Create(promise)); + let result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id).await; + assert!(result.is_ok(), "{:?}", result.err()); + + // This is known because we are using a fixed private key for the signer + let deployed_address = Address::decode("bda6e7f87c816d25718c38b1c753e280f9455350").unwrap(); + let code = aurora.get_code(deployed_address).await.unwrap().result; + + assert_eq!( + code, expected_code, + "Failed to properly deploy EVM code via XCC" + ); + } + + #[tokio::test] + async fn test_xcc_precompile_eager() { + test_xcc_precompile_common(false).await; + } + + #[tokio::test] + async fn test_xcc_precompile_scheduled() { + test_xcc_precompile_common(true).await; + } + + /// This test uses the XCC feature where the promise has many nested callbacks. + /// The contract it uses is one which computes Fibonacci numbers in an inefficient way. + /// The contract has two functions: `seed` and `accumulate`. + /// The `seed` function always returns `{"a": "0", "b": "1"}`. + /// The `accumulate` function performs one step of the Fibonacci recursion relation using + /// a promise result (i.e. result from prior call) as input. + /// Therefore, we can compute Fibonacci numbers by creating a long chain of callbacks. + /// For example, to compute the 6th number: + /// `seed.then(accumulate).then(accumulate).then(accumulate).then(accumulate).then(accumulate)`. + #[tokio::test] + async fn test_xcc_multiple_callbacks() { + let XccTestContext { + aurora, + mut signer, + signer_address, + chain_id, + .. + } = init_xcc().await.unwrap(); + + // 1. Deploy Fibonacci contract + let fib_account_id = deploy_fibonacci(&aurora).await.unwrap(); + + // 2. Create XCC account, schedule Fibonacci call + let n = 6; + let promise = super::make_fib_promise(n, &fib_account_id); + let xcc_args = CrossContractCallArgs::Delayed(PromiseArgs::Recursive(promise)); + let result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id).await; + assert!(result.is_ok(), "{:?}", result.err()); + + // 3. Make Fibonacci call + let router_account = format!( + "{}.{}", + hex::encode(signer_address.as_bytes()), + aurora.id().as_ref() + ); + let result = aurora + .root() + .call(&router_account.parse().unwrap(), "execute_scheduled") + .args_json(json!({"nonce": "0"})) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success(), "{result:?}"); + + // 4. Check the result is correct + let output = result.json().unwrap(); + check_fib_result(&output, n); + } + + // This test is similar to `test_xcc_multiple_callbacks`, but instead of computing + // Fibonacci numbers through repeated callbacks, it uses the `And` promise combinator. + #[tokio::test] + async fn test_xcc_and_combinator() { + let XccTestContext { + aurora, + mut signer, + signer_address, + chain_id, + .. + } = init_xcc().await.unwrap(); + + // 1. Deploy Fibonacci contract + let fib_account_id = deploy_fibonacci(&aurora).await.unwrap(); + + // 2. Create XCC account, schedule Fibonacci call + let n = 6; + let promise = NearPromise::Then { + base: Box::new(NearPromise::And(vec![ + NearPromise::Simple(SimpleNearPromise::Create(PromiseCreateArgs { + target_account_id: fib_account_id.clone(), + method: "fib".into(), + args: format!(r#"{{"n": {}}}"#, n - 1).into_bytes(), + attached_balance: Yocto::new(0), + attached_gas: NearGas::new(10_000_000_000_000_u64 * n), + })), + NearPromise::Simple(SimpleNearPromise::Create(PromiseCreateArgs { + target_account_id: fib_account_id.clone(), + method: "fib".into(), + args: format!(r#"{{"n": {}}}"#, n - 2).into_bytes(), + attached_balance: Yocto::new(0), + attached_gas: NearGas::new(10_000_000_000_000_u64 * n), + })), + ])), + callback: SimpleNearPromise::Create(PromiseCreateArgs { + target_account_id: fib_account_id, + method: "sum".into(), + args: Vec::new(), + attached_balance: Yocto::new(0), + attached_gas: NearGas::new(5_000_000_000_000), + }), + }; + let xcc_args = CrossContractCallArgs::Delayed(PromiseArgs::Recursive(promise)); + let result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id).await; + assert!(result.is_ok(), "{:?}", result.err()); + + // 3. Make Fibonacci call + let router_account = format!( + "{}.{}", + hex::encode(signer_address.as_bytes()), + aurora.id().as_ref() + ); + let result = aurora + .root() + .call(&router_account.parse().unwrap(), "execute_scheduled") + .args_json(json!({"nonce": "0"})) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success(), "{result:?}"); + + // 4. Check the result is correct + let output = result.json().unwrap(); + check_fib_result(&output, usize::try_from(n).unwrap()); + } + + #[allow(clippy::too_many_lines)] + async fn test_xcc_precompile_common(is_scheduled: bool) { + let XccTestContext { + aurora, + mut signer, + signer_address, + chain_id, + wnear_account, + } = init_xcc().await.unwrap(); + + let router_account = format!( + "{}.{}", + hex::encode(signer_address.as_bytes()), + aurora.id().as_ref() + ); + let router_account_id = router_account.parse().unwrap(); + + // 1. Deploy NEP-141 token. + let ft_owner = create_sub_account(&aurora.root(), "ft_owner", STORAGE_AMOUNT) + .await + .unwrap(); + let token = create_sub_account(&aurora.root(), "test_token", STORAGE_AMOUNT) + .await + .unwrap(); + let nep_141_supply = 500; + let nep_141 = deploy_nep_141(&token, &ft_owner, nep_141_supply, &aurora) + .await + .unwrap(); + + // 2. Register EVM router contract + let result = aurora + .root() + .call(&nep_141.id(), "storage_deposit") + .args_json(json!({ + "account_id": router_account, + })) + .deposit(STORAGE_AMOUNT) + .transact() + .await + .unwrap(); + assert!(result.is_success()); + + // 3. Give router some tokens + let transfer_amount: u128 = 199; + let result = ft_owner + .call(&nep_141.id(), "ft_transfer") + .args_json(json!({ + "receiver_id": router_account, + "amount": format!("{transfer_amount}"), + })) + .deposit(1) + .transact() + .await + .unwrap(); + assert!(result.is_success()); + assert_eq!( + nep_141_balance_of(&nep_141, &ft_owner.id()).await, + nep_141_supply - transfer_amount + ); + + // 4. Use xcc precompile to send those tokens back + let args = json!({ + "receiver_id": ft_owner.id().as_ref(), + "amount": format!("{transfer_amount}"), + }) + .to_string(); + let promise = PromiseCreateArgs { + target_account_id: nep_141.id(), + method: "ft_transfer".into(), + args: args.into_bytes(), + attached_balance: Yocto::new(1), + attached_gas: NearGas::new(100_000_000_000_000), + }; + let callback = PromiseCreateArgs { + target_account_id: nep_141.id(), + method: "ft_balance_of".into(), + args: format!(r#"{{"account_id":"{router_account}"}}"#).into_bytes(), + attached_balance: Yocto::new(0), + attached_gas: NearGas::new(2_000_000_000_000), + }; + let promise_args = PromiseArgs::Callback(PromiseWithCallbackArgs { + base: promise, + callback, + }); + let xcc_args = if is_scheduled { + CrossContractCallArgs::Delayed(promise_args) + } else { + CrossContractCallArgs::Eager(promise_args) + }; + let engine_balance_before_xcc = get_engine_near_balance(&aurora).await; + let result = submit_xcc_transaction(&xcc_args, &aurora, &mut signer, chain_id).await; + assert!(result.is_ok(), "{:?}", result.err()); + + let engine_balance_after_xcc = get_engine_near_balance(&aurora).await; + assert!( + // engine loses less than 0.01 NEAR + engine_balance_after_xcc.max(engine_balance_before_xcc) + - engine_balance_after_xcc.min(engine_balance_before_xcc) + < 10_000_000_000_000_000_000_000, + "Engine lost too much NEAR funding xcc: Before={engine_balance_before_xcc} After={engine_balance_after_xcc}", + ); + + let router_balance = aurora.node.get_balance(&router_account_id).await.unwrap(); + assert!( + // router loses less than 0.01 NEAR from its allocated funds + aurora_engine_precompiles::xcc::state::STORAGE_AMOUNT.as_u128() - router_balance + < 10_000_000_000_000_000_000_000, + "Router lost too much NEAR: Balance={router_balance}", + ); + // Router has no wNEAR balance because it all was unwrapped to actual NEAR + assert_eq!( + nep_141_balance_of(&wnear_account, &router_account_id).await, + 0, + ); + + if is_scheduled { + // The promise was only scheduled, not executed immediately. So the FT balance has not changed yet. + assert_eq!( + nep_141_balance_of(&nep_141, &ft_owner.id()).await, + nep_141_supply - transfer_amount + ); + + // Now we execute the scheduled promise + let result = aurora + .root() + .call(&router_account_id, "execute_scheduled") + .args_json(json!({ + "nonce": "0" + })) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success(), "{result:?}"); + } + + assert_eq!( + nep_141_balance_of(&nep_141, &ft_owner.id()).await, + nep_141_supply + ); + } + + /// Deploys the EVM, sets xcc router code, deploys wnear contract, bridges wnear into EVM, + /// and calls `factory_set_wnear_address` + async fn init_xcc() -> anyhow::Result { + let aurora = deploy_engine().await; + let chain_id = aurora.get_chain_id().await?.result.as_u64(); + + let xcc_wasm_bytes = super::contract_bytes(); + let result = aurora.factory_update(xcc_wasm_bytes).transact().await?; + assert!(result.is_success()); + + let mut signer = utils::Signer::random(); + let signer_address = utils::address_from_secret_key(&signer.secret_key); + + // Setup wNEAR contract and bridge it to Aurora + let wnear_contract = deploy_wnear(&aurora).await?; + let wnear_erc20 = deploy_erc20_from_nep_141(wnear_contract.id().as_ref(), &aurora).await?; + + transfer_nep_141_to_erc_20( + &wnear_contract, + &wnear_erc20, + &aurora.root(), + signer_address, + WNEAR_AMOUNT, + &aurora, + ) + .await + .unwrap(); + let result = aurora + .factory_set_wnear_address(wnear_erc20.0.address) + .transact() + .await?; + assert!(result.is_success()); + + let approve_tx = wnear_erc20.approve( + cross_contract_call::ADDRESS, + WNEAR_AMOUNT.into(), + signer.use_nonce().into(), + ); + let signed_transaction = + utils::sign_transaction(approve_tx, Some(chain_id), &signer.secret_key); + let result = aurora + .submit(rlp::encode(&signed_transaction).to_vec()) + .transact() + .await?; + assert!(result.is_success()); + + Ok(XccTestContext { + aurora, + signer, + signer_address, + chain_id, + wnear_account: wnear_contract, + }) + } + + struct XccTestContext { + pub aurora: EngineContract, + pub signer: utils::Signer, + pub signer_address: Address, + pub chain_id: u64, + pub wnear_account: RawContract, + } + + async fn submit_xcc_transaction( + xcc_args: &CrossContractCallArgs, + aurora: &EngineContract, + signer: &mut utils::Signer, + chain_id: u64, + ) -> anyhow::Result<()> { + let transaction = TransactionLegacy { + nonce: signer.use_nonce().into(), + gas_price: 0u64.into(), + gas_limit: u64::MAX.into(), + to: Some(cross_contract_call::ADDRESS), + value: Wei::zero(), + data: xcc_args.try_to_vec().unwrap(), + }; + let signed_transaction = + utils::sign_transaction(transaction, Some(chain_id), &signer.secret_key); + let result = aurora + .submit(rlp::encode(&signed_transaction).to_vec()) + .max_gas() + .transact() + .await?; + + match &result.value().status { + TransactionStatus::Succeed(_) => Ok(()), + TransactionStatus::Revert(b) => { + let revert_message = ethabi::decode(&[ethabi::ParamType::String], &b[4..]) + .unwrap() + .pop() + .unwrap() + .into_string() + .unwrap(); + anyhow::bail!("TX has been reverted with message: {revert_message}"); + } + _ => anyhow::bail!("Wrong status of the transaction"), + } + } + + async fn get_engine_near_balance(aurora: &EngineContract) -> u128 { + aurora.ft_balance_of(&aurora.id()).await.unwrap().result.0 + } + + async fn deploy_wnear(aurora: &EngineContract) -> anyhow::Result { + let contract_bytes = std::fs::read("src/tests/res/w_near.wasm").unwrap(); + let wrap_account = create_sub_account(&aurora.root(), "wrap", STORAGE_AMOUNT).await?; + let contract = wrap_account.deploy(&contract_bytes).await?; + + let result = aurora.root().call(&contract.id(), "new").transact().await?; + assert!(result.is_success(), "{result:?}"); + + // Need to register Aurora contract so that it can receive tokens + let result = aurora + .root() + .call(&wrap_account.id(), "storage_deposit") + .args_json(json!({"account_id": aurora.id().as_ref()})) + .deposit(STORAGE_AMOUNT) + .transact() + .await?; + assert!(result.is_success(), "{result:?}"); + + // Also need to register root account + let result = aurora + .root() + .call(&wrap_account.id(), "storage_deposit") + .args_json(json!({"account_id": aurora.root().id().as_ref()})) + .deposit(STORAGE_AMOUNT) + .transact() + .await?; + assert!(result.is_success(), "{result:?}"); + + // Mint some wNEAR for the root account to use + let result = aurora + .root() + .call(&wrap_account.id(), "near_deposit") + .deposit(WNEAR_AMOUNT) + .transact() + .await?; + assert!(result.is_success(), "{result:?}"); + + Ok(contract) + } + + async fn deploy_fibonacci(aurora: &EngineContract) -> anyhow::Result { + let fib_contract_bytes = { + let base_path = Path::new("..").join("etc").join("tests").join("fibonacci"); + let output_path = + base_path.join("target/wasm32-unknown-unknown/release/fibonacci_on_near.wasm"); + utils::rust::compile(base_path); + std::fs::read(output_path)? + }; + let fib_account = create_sub_account(&aurora.root(), "fib", parse_near!("50 N")).await?; + fib_account + .deploy(&fib_contract_bytes) + .await + .map(|contract| contract.id()) + } +} diff --git a/engine-tests/src/test_utils/mocked_external.rs b/engine-tests/src/utils/mocked_external.rs similarity index 79% rename from engine-tests/src/test_utils/mocked_external.rs rename to engine-tests/src/utils/mocked_external.rs index 003257832..13718d4d4 100644 --- a/engine-tests/src/test_utils/mocked_external.rs +++ b/engine-tests/src/utils/mocked_external.rs @@ -1,4 +1,7 @@ +use near_vm_errors::VMLogicError; use near_vm_logic::mocks::mock_external::MockedExternal; +use near_vm_logic::StorageGetMode; +use std::cell::Cell; /// Derived from mainnet data reported here: `https://hackmd.io/@birchmd/r1HRjr0P9` /// Uses the formulas: @@ -20,16 +23,16 @@ pub const MAINNET_AVERAGE_TRIE_DEPTH: u64 = 13; #[derive(Clone)] pub struct MockedExternalWithTrie { pub underlying: MockedExternal, - new_trie_node_count: std::cell::Cell, - cached_trie_node_count: std::cell::Cell, + new_trie_node_count: Cell, + cached_trie_node_count: Cell, } impl MockedExternalWithTrie { pub const fn new(ext: MockedExternal) -> Self { Self { underlying: ext, - new_trie_node_count: std::cell::Cell::new(0), - cached_trie_node_count: std::cell::Cell::new(0), + new_trie_node_count: Cell::new(0), + cached_trie_node_count: Cell::new(0), } } @@ -45,7 +48,7 @@ impl MockedExternalWithTrie { } impl near_vm_logic::External for MockedExternalWithTrie { - fn storage_set(&mut self, key: &[u8], value: &[u8]) -> Result<(), near_vm_logic::VMLogicError> { + fn storage_set(&mut self, key: &[u8], value: &[u8]) -> Result<(), VMLogicError> { self.increment_new_trie_node_count(MAINNET_AVERAGE_TRIE_DEPTH); self.underlying.storage_set(key, value) } @@ -54,36 +57,23 @@ impl near_vm_logic::External for MockedExternalWithTrie { &'a self, key: &[u8], mode: near_vm_logic::StorageGetMode, - ) -> Result>, near_vm_logic::VMLogicError> { + ) -> Result>, VMLogicError> { self.increment_new_trie_node_count(MAINNET_AVERAGE_TOUCHED_TRIE_PER_READ); self.increment_cached_trie_node_count(MAINNET_AVERAGE_READ_CACHED_TRIE_PER_READ); self.underlying.storage_get(key, mode) } - fn storage_remove(&mut self, key: &[u8]) -> Result<(), near_vm_logic::VMLogicError> { + fn storage_remove(&mut self, key: &[u8]) -> Result<(), VMLogicError> { self.increment_new_trie_node_count(MAINNET_AVERAGE_TRIE_DEPTH); self.underlying.storage_remove(key) } - fn storage_remove_subtree(&mut self, prefix: &[u8]) -> Result<(), near_vm_logic::VMLogicError> { + fn storage_remove_subtree(&mut self, prefix: &[u8]) -> Result<(), VMLogicError> { self.underlying.storage_remove_subtree(prefix) } - fn storage_has_key(&mut self, key: &[u8]) -> Result { - self.underlying.storage_has_key(key) - } - - fn validator_stake( - &self, - account_id: &near_primitives::types::AccountId, - ) -> Result, near_vm_logic::VMLogicError> { - self.underlying.validator_stake(account_id) - } - - fn validator_total_stake( - &self, - ) -> Result { - self.underlying.validator_total_stake() + fn storage_has_key(&mut self, key: &[u8], mode: StorageGetMode) -> Result { + self.underlying.storage_has_key(key, mode) } fn generate_data_id(&mut self) -> near_primitives::hash::CryptoHash { @@ -98,4 +88,15 @@ impl near_vm_logic::External for MockedExternalWithTrie { mem_reads, } } + + fn validator_stake( + &self, + account_id: &near_primitives::types::AccountId, + ) -> Result, VMLogicError> { + self.underlying.validator_stake(account_id) + } + + fn validator_total_stake(&self) -> Result { + self.underlying.validator_total_stake() + } } diff --git a/engine-tests/src/test_utils/mod.rs b/engine-tests/src/utils/mod.rs similarity index 97% rename from engine-tests/src/test_utils/mod.rs rename to engine-tests/src/utils/mod.rs index 56db405f3..357987e4c 100644 --- a/engine-tests/src/test_utils/mod.rs +++ b/engine-tests/src/utils/mod.rs @@ -1,8 +1,8 @@ use aurora_engine::engine::{EngineError, EngineErrorKind, GasPaymentError}; use aurora_engine::parameters::{SubmitArgs, ViewCallArgs}; use aurora_engine_types::account_id::AccountId; +use aurora_engine_types::borsh::{BorshDeserialize, BorshSerialize}; use aurora_engine_types::types::{NEP141Wei, PromiseResult}; -use borsh::{BorshDeserialize, BorshSerialize}; use evm::ExitFatal; use libsecp256k1::{self, Message, PublicKey, SecretKey}; use near_primitives::runtime::config_store::RuntimeConfigStore; @@ -29,7 +29,7 @@ use crate::prelude::transactions::{ legacy::{LegacyEthSignedTransaction, TransactionLegacy}, }; use crate::prelude::{sdk, Address, Wei, H256, U256}; -use crate::test_utils::solidity::{ContractConstructor, DeployedContract}; +use crate::utils::solidity::{ContractConstructor, DeployedContract}; // TODO(Copied from #84): Make sure that there is only one Signer after both PR are merged. pub const ORIGIN: &str = "aurora"; @@ -47,18 +47,12 @@ pub const RESUME_CONTRACT: &str = "resume_contract"; const CALLER_ACCOUNT_ID: &str = "some-account.near"; -pub mod erc20; -pub mod exit_precompile; pub mod mocked_external; pub mod one_inch; -pub mod random; pub mod rust; -pub mod self_destruct; pub mod solidity; pub mod standalone; -pub mod standard_precompiles; -pub mod uniswap; -pub mod weth; +pub mod workspace; pub struct Signer { pub nonce: u64, @@ -180,8 +174,8 @@ impl AuroraRunner { context.block_height += 1; context.block_timestamp += 1_000_000_000; context.input = input; - context.signer_account_id = as_account_id(signer_account_id); - context.predecessor_account_id = as_account_id(caller_account_id); + context.signer_account_id = signer_account_id.parse().unwrap(); + context.predecessor_account_id = caller_account_id.parse().unwrap(); } pub fn call( @@ -579,6 +573,7 @@ impl Default for AuroraRunner { let runtime_config_store = RuntimeConfigStore::new(None); let runtime_config = runtime_config_store.get_config(PROTOCOL_VERSION); let wasm_config = runtime_config.wasm_config.clone(); + let origin_account_id: near_primitives::types::AccountId = ORIGIN.parse().unwrap(); Self { aurora_account_id: ORIGIN.to_string(), @@ -587,10 +582,10 @@ impl Default for AuroraRunner { cache: MockCompiledContractCache::default(), ext: mocked_external::MockedExternalWithTrie::new(MockedExternal::default()), context: VMContext { - current_account_id: as_account_id(ORIGIN), - signer_account_id: as_account_id(ORIGIN), + current_account_id: origin_account_id.clone(), + signer_account_id: origin_account_id.clone(), signer_account_pk: vec![], - predecessor_account_id: as_account_id(ORIGIN), + predecessor_account_id: origin_account_id, input: vec![], block_height: 0, block_timestamp: 0, @@ -639,7 +634,7 @@ impl ExecutionProfile { } } -pub fn deploy_evm() -> AuroraRunner { +pub fn deploy_runner() -> AuroraRunner { let mut runner = AuroraRunner::default(); let args = LegacyNewCallArgs { chain_id: crate::prelude::u256_to_arr(&U256::from(runner.chain_id)), @@ -840,13 +835,8 @@ pub fn address_from_hex(address: &str) -> Address { Address::try_from_slice(&bytes).unwrap() } -pub fn as_account_id(account_id: &str) -> near_primitives_core::types::AccountId { - account_id.parse().unwrap() -} - pub fn str_to_account_id(account_id: &str) -> AccountId { - use aurora_engine_types::str::FromStr; - AccountId::from_str(account_id).unwrap() + account_id.parse().unwrap() } pub fn unwrap_success(result: SubmitResult) -> Vec { @@ -863,8 +853,8 @@ pub fn unwrap_success_slice(result: &SubmitResult) -> &[u8] { } } -pub fn unwrap_revert(result: SubmitResult) -> Vec { - match result.status { +pub fn unwrap_revert_slice(result: &SubmitResult) -> &[u8] { + match &result.status { TransactionStatus::Revert(ret) => ret, other => panic!("Unexpected status: {other:?}"), } diff --git a/engine-tests/src/test_utils/one_inch/liquidity_protocol.rs b/engine-tests/src/utils/one_inch/liquidity_protocol.rs similarity index 83% rename from engine-tests/src/test_utils/one_inch/liquidity_protocol.rs rename to engine-tests/src/utils/one_inch/liquidity_protocol.rs index da96bb3e2..66cb11068 100644 --- a/engine-tests/src/test_utils/one_inch/liquidity_protocol.rs +++ b/engine-tests/src/utils/one_inch/liquidity_protocol.rs @@ -1,6 +1,7 @@ use crate::prelude::parameters::SubmitResult; use crate::prelude::{Address, U256}; -use crate::test_utils::{self, solidity, ExecutionProfile}; +use crate::utils::solidity::erc20::{ERC20Constructor, ERC20}; +use crate::utils::{self, solidity, ExecutionProfile}; use aurora_engine_types::types::Wei; use std::path::PathBuf; use std::sync::Once; @@ -9,8 +10,8 @@ static DOWNLOAD_ONCE: Once = Once::new(); static COMPILE_ONCE: Once = Once::new(); pub struct Helper<'a> { - pub runner: &'a mut test_utils::AuroraRunner, - pub signer: &'a mut test_utils::Signer, + pub runner: &'a mut utils::AuroraRunner, + pub signer: &'a mut utils::Signer, } impl<'a> Helper<'a> { @@ -18,10 +19,9 @@ impl<'a> Helper<'a> { &mut self, ) -> (SubmitResult, ExecutionProfile, PoolDeployer) { let artifacts_path = download_and_compile_solidity_sources(); - let deployer_constructor = - test_utils::solidity::ContractConstructor::compile_from_extended_json( - artifacts_path.join("MooniswapDeployer.sol/MooniswapDeployer.json"), - ); + let deployer_constructor = utils::solidity::ContractConstructor::compile_from_extended_json( + artifacts_path.join("MooniswapDeployer.sol/MooniswapDeployer.json"), + ); let data = deployer_constructor.code; let abi = deployer_constructor.abi; @@ -40,7 +40,7 @@ impl<'a> Helper<'a> { .unwrap(); let deployer_address = - Address::try_from_slice(test_utils::unwrap_success_slice(&result)).unwrap(); + Address::try_from_slice(utils::unwrap_success_slice(&result)).unwrap(); let deployer = PoolDeployer(solidity::DeployedContract { abi, address: deployer_address, @@ -54,11 +54,11 @@ impl<'a> Helper<'a> { pool_deployer: &PoolDeployer, ) -> (SubmitResult, ExecutionProfile, PoolFactory) { let artifacts_path = download_and_compile_solidity_sources(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_extended_json( + let constructor = utils::solidity::ContractConstructor::compile_from_extended_json( artifacts_path.join("MooniswapFactory.sol/MooniswapFactory.json"), ); - let signer_address = test_utils::address_from_secret_key(&self.signer.secret_key); + let signer_address = utils::address_from_secret_key(&self.signer.secret_key); let (result, profile) = self .runner .submit_with_signer_profiled(self.signer, |nonce| { @@ -73,7 +73,7 @@ impl<'a> Helper<'a> { }) .unwrap(); - let address = Address::try_from_slice(test_utils::unwrap_success_slice(&result)).unwrap(); + let address = Address::try_from_slice(utils::unwrap_success_slice(&result)).unwrap(); let pool_factory = PoolFactory(constructor.deployed_at(address)); (result, profile, pool_factory) @@ -86,7 +86,7 @@ impl<'a> Helper<'a> { token_b: Address, ) -> (SubmitResult, ExecutionProfile, Pool) { let artifacts_path = download_and_compile_solidity_sources(); - let constructor = test_utils::solidity::ContractConstructor::compile_from_extended_json( + let constructor = solidity::ContractConstructor::compile_from_extended_json( artifacts_path.join("Mooniswap.sol/Mooniswap.json"), ); @@ -105,27 +105,23 @@ impl<'a> Helper<'a> { .unwrap(); let address = - Address::try_from_slice(&test_utils::unwrap_success_slice(&result)[12..32]).unwrap(); + Address::try_from_slice(&utils::unwrap_success_slice(&result)[12..32]).unwrap(); let pool = Pool(constructor.deployed_at(address)); (result, profile, pool) } - pub(crate) fn create_erc20(&mut self, name: &str, symbol: &str) -> test_utils::erc20::ERC20 { - let constructor = test_utils::erc20::ERC20Constructor::load(); + pub(crate) fn create_erc20(&mut self, name: &str, symbol: &str) -> ERC20 { + let constructor = ERC20Constructor::load(); let nonce = self.signer.use_nonce(); - test_utils::erc20::ERC20(self.runner.deploy_contract( + ERC20(self.runner.deploy_contract( &self.signer.secret_key, |c| c.deploy(name, symbol, nonce.into()), constructor, )) } - pub(crate) fn mint_erc20_tokens( - &mut self, - token: &test_utils::erc20::ERC20, - dest: Address, - ) -> SubmitResult { + pub(crate) fn mint_erc20_tokens(&mut self, token: &ERC20, dest: Address) -> SubmitResult { let result = self .runner .submit_with_signer(self.signer, |nonce| { @@ -136,11 +132,7 @@ impl<'a> Helper<'a> { result } - pub(crate) fn approve_erc20_tokens( - &mut self, - token: &test_utils::erc20::ERC20, - dest: Address, - ) -> SubmitResult { + pub(crate) fn approve_erc20_tokens(&mut self, token: &ERC20, dest: Address) -> SubmitResult { let result = self .runner .submit_with_signer(self.signer, |nonce| { diff --git a/engine-tests/src/test_utils/one_inch/mod.rs b/engine-tests/src/utils/one_inch/mod.rs similarity index 87% rename from engine-tests/src/test_utils/one_inch/mod.rs rename to engine-tests/src/utils/one_inch/mod.rs index 06036dce4..914415bd4 100644 --- a/engine-tests/src/test_utils/one_inch/mod.rs +++ b/engine-tests/src/utils/one_inch/mod.rs @@ -36,7 +36,10 @@ pub fn download_and_compile_solidity_sources( .args(["yarn", "install"]) .status() .unwrap(); - assert!(status.success()); + assert!( + status.success(), + "Unsuccessful exit status while install hardhat dependencies: {status}" + ); let hardhat = |command: &str| { let status = Command::new("/usr/bin/env") @@ -44,7 +47,10 @@ pub fn download_and_compile_solidity_sources( .args(["node_modules/hardhat/internal/cli/cli.js", command]) .status() .unwrap(); - assert!(status.success()); + assert!( + status.success(), + "Unsuccessful exit status while install while executing `{command}`: {status}", + ); }; // clean and compile diff --git a/engine-tests/src/test_utils/rust.rs b/engine-tests/src/utils/rust.rs similarity index 100% rename from engine-tests/src/test_utils/rust.rs rename to engine-tests/src/utils/rust.rs diff --git a/engine-tests/src/test_utils/erc20.rs b/engine-tests/src/utils/solidity/erc20.rs similarity index 99% rename from engine-tests/src/test_utils/erc20.rs rename to engine-tests/src/utils/solidity/erc20.rs index 9fba895d5..eea55da60 100644 --- a/engine-tests/src/test_utils/erc20.rs +++ b/engine-tests/src/utils/solidity/erc20.rs @@ -1,5 +1,5 @@ use crate::prelude::{transactions::legacy::TransactionLegacy, Address, U256}; -use crate::test_utils::solidity; +use crate::utils::solidity; use aurora_engine_transactions::NormalizedEthTransaction; use aurora_engine_types::types::Wei; use std::path::{Path, PathBuf}; diff --git a/engine-tests/src/test_utils/exit_precompile.rs b/engine-tests/src/utils/solidity/exit_precompile.rs similarity index 96% rename from engine-tests/src/test_utils/exit_precompile.rs rename to engine-tests/src/utils/solidity/exit_precompile.rs index 2cbb6a0f4..11f24ecbf 100644 --- a/engine-tests/src/test_utils/exit_precompile.rs +++ b/engine-tests/src/utils/solidity/exit_precompile.rs @@ -2,7 +2,7 @@ use crate::prelude::{ make_address, parameters::SubmitResult, transactions::legacy::TransactionLegacy, Address, Wei, U256, }; -use crate::test_utils::{self, solidity, AuroraRunner, Signer}; +use crate::utils::{self, solidity, AuroraRunner, Signer}; use aurora_engine::engine::EngineError; pub struct TesterConstructor(pub solidity::ContractConstructor); @@ -36,10 +36,10 @@ impl TesterConstructor { TransactionLegacy { nonce: nonce.into(), - gas_price: U256::default(), + gas_price: U256::zero(), gas_limit: U256::from(DEPLOY_CONTRACT_GAS), to: None, - value: Wei::default(), + value: Wei::zero(), data, } } @@ -114,7 +114,7 @@ impl Tester { &[ethabi::Token::String(name)], ) .unwrap(); - let output_bytes = test_utils::unwrap_success(result); + let output_bytes = utils::unwrap_success(result); let output = ethabi::decode(output_type, &output_bytes).unwrap(); match &output[..] { diff --git a/engine-tests/src/test_utils/solidity.rs b/engine-tests/src/utils/solidity/mod.rs similarity index 97% rename from engine-tests/src/test_utils/solidity.rs rename to engine-tests/src/utils/solidity/mod.rs index 68e41b174..11d5d3586 100644 --- a/engine-tests/src/test_utils/solidity.rs +++ b/engine-tests/src/utils/solidity/mod.rs @@ -6,6 +6,14 @@ use std::io::BufReader; use std::path::Path; use std::process::Command; +pub mod erc20; +pub mod exit_precompile; +pub mod random; +pub mod self_destruct; +pub mod standard_precompiles; +pub mod uniswap; +pub mod weth; + pub struct ContractConstructor { pub abi: ethabi::Contract, pub code: Vec, diff --git a/engine-tests/src/test_utils/random.rs b/engine-tests/src/utils/solidity/random.rs similarity index 94% rename from engine-tests/src/test_utils/random.rs rename to engine-tests/src/utils/solidity/random.rs index 33711d939..36a821809 100644 --- a/engine-tests/src/test_utils/random.rs +++ b/engine-tests/src/utils/solidity/random.rs @@ -1,5 +1,5 @@ use crate::prelude::U256; -use crate::test_utils::{self, solidity, AuroraRunner, Signer}; +use crate::utils::{self, solidity, AuroraRunner, Signer}; use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::types::Wei; use aurora_engine_types::H256; @@ -66,7 +66,7 @@ impl Random { }; let result = runner.submit_transaction(&signer.secret_key, tx).unwrap(); - let result = test_utils::unwrap_success(result); + let result = utils::unwrap_success(result); let mut random_seed = [0; 32]; random_seed.copy_from_slice(result.as_slice()); diff --git a/engine-tests/src/test_utils/self_destruct.rs b/engine-tests/src/utils/solidity/self_destruct.rs similarity index 96% rename from engine-tests/src/test_utils/self_destruct.rs rename to engine-tests/src/utils/solidity/self_destruct.rs index ec1e7acf1..26ffa21ec 100644 --- a/engine-tests/src/test_utils/self_destruct.rs +++ b/engine-tests/src/utils/solidity/self_destruct.rs @@ -2,9 +2,9 @@ use crate::prelude::{ parameters::CallArgs, parameters::FunctionCallArgsV2, transactions::legacy::TransactionLegacy, Address, WeiU256, U256, }; -use crate::test_utils::{self, solidity, AuroraRunner, Signer}; +use crate::utils::{self, solidity, AuroraRunner, Signer}; +use aurora_engine_types::borsh::BorshSerialize; use aurora_engine_types::types::Wei; -use borsh::BorshSerialize; pub struct SelfDestructFactoryConstructor(pub solidity::ContractConstructor); @@ -73,7 +73,7 @@ impl SelfDestructFactory { }; let result = runner.submit_transaction(&signer.secret_key, tx).unwrap(); - let result = test_utils::unwrap_success(result); + let result = utils::unwrap_success(result); Address::try_from_slice(&result[12..]).unwrap() } @@ -113,7 +113,7 @@ impl SelfDestruct { }; let result = runner.submit_transaction(&signer.secret_key, tx).unwrap(); - let result = test_utils::unwrap_success(result); + let result = utils::unwrap_success(result); if result.len() == 32 { Some(u128::from_be_bytes(result[16..32].try_into().unwrap())) diff --git a/engine-tests/src/test_utils/standard_precompiles.rs b/engine-tests/src/utils/solidity/standard_precompiles.rs similarity index 97% rename from engine-tests/src/test_utils/standard_precompiles.rs rename to engine-tests/src/utils/solidity/standard_precompiles.rs index 8d57495cb..5e58cfe8a 100644 --- a/engine-tests/src/test_utils/standard_precompiles.rs +++ b/engine-tests/src/utils/solidity/standard_precompiles.rs @@ -1,5 +1,5 @@ use crate::prelude::{transactions::legacy::TransactionLegacy, U256}; -use crate::test_utils::solidity; +use crate::utils::solidity; use std::path::{Path, PathBuf}; pub struct PrecompilesConstructor(pub solidity::ContractConstructor); diff --git a/engine-tests/src/test_utils/uniswap.rs b/engine-tests/src/utils/solidity/uniswap.rs similarity index 99% rename from engine-tests/src/test_utils/uniswap.rs rename to engine-tests/src/utils/solidity/uniswap.rs index f7b7aadba..f5b6546f0 100644 --- a/engine-tests/src/test_utils/uniswap.rs +++ b/engine-tests/src/utils/solidity/uniswap.rs @@ -1,5 +1,5 @@ use crate::prelude::{Address, U256}; -use crate::test_utils::solidity; +use crate::utils::solidity; use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::types::Wei; use std::ops::Not; @@ -152,10 +152,10 @@ impl Factory { TransactionLegacy { nonce, - gas_price: U256::default(), + gas_price: U256::zero(), gas_limit: u64::MAX.into(), to: Some(self.0.address), - value: Wei::default(), + value: Wei::zero(), data, } } diff --git a/engine-tests/src/test_utils/weth.rs b/engine-tests/src/utils/solidity/weth.rs similarity index 97% rename from engine-tests/src/test_utils/weth.rs rename to engine-tests/src/utils/solidity/weth.rs index 63ff6cc17..0a1d201b9 100644 --- a/engine-tests/src/test_utils/weth.rs +++ b/engine-tests/src/utils/solidity/weth.rs @@ -2,7 +2,7 @@ use aurora_engine_transactions::legacy::TransactionLegacy; use aurora_engine_types::types::{Address, Wei}; use aurora_engine_types::U256; -use crate::test_utils::solidity; +use crate::utils::solidity; pub struct WethConstructor(solidity::ContractConstructor); diff --git a/engine-tests/src/test_utils/standalone/mocks/block.rs b/engine-tests/src/utils/standalone/mocks/block.rs similarity index 100% rename from engine-tests/src/test_utils/standalone/mocks/block.rs rename to engine-tests/src/utils/standalone/mocks/block.rs diff --git a/engine-tests/src/test_utils/standalone/mocks/mod.rs b/engine-tests/src/utils/standalone/mocks/mod.rs similarity index 95% rename from engine-tests/src/test_utils/standalone/mocks/mod.rs rename to engine-tests/src/utils/standalone/mocks/mod.rs index 970621013..0d1f35249 100644 --- a/engine-tests/src/test_utils/standalone/mocks/mod.rs +++ b/engine-tests/src/utils/standalone/mocks/mod.rs @@ -1,4 +1,4 @@ -use crate::test_utils; +use crate::utils; use aurora_engine::fungible_token::FungibleTokenMetadata; use aurora_engine::parameters::{ FinishDepositCallArgs, InitCallArgs, NEP141FtOnTransferArgs, NewCallArgsV2, @@ -9,10 +9,10 @@ use aurora_engine_sdk::io::IO; use aurora_engine_types::types::{make_address, Address, Balance, NEP141Wei, NearGas, Wei}; use aurora_engine_types::{account_id::AccountId, H256, U256}; use engine_standalone_storage::{BlockMetadata, Storage}; -use near_sdk_sim::DEFAULT_GAS; pub mod block; +const DEFAULT_GAS: u64 = 300_000_000_000_000; pub const ETH_CUSTODIAN_ADDRESS: Address = make_address(0xd045f7e1, 0x9b2488924b97f9c145b5e51d0d895a65); @@ -32,7 +32,7 @@ pub fn insert_block(storage: &mut Storage, block_height: u64) { } pub fn default_env(block_height: u64) -> aurora_engine_sdk::env::Fixed { - let aurora_id: AccountId = test_utils::AuroraRunner::default() + let aurora_id: AccountId = utils::AuroraRunner::default() .aurora_account_id .parse() .unwrap(); @@ -58,7 +58,7 @@ pub fn init_evm(mut io: I, env: &E, chain_id: u64) { state::set_state(&mut io, &new_args.into()).unwrap(); let connector_args = InitCallArgs { - prover_account: test_utils::str_to_account_id("prover.near"), + prover_account: utils::str_to_account_id("prover.near"), eth_custodian_address: ETH_CUSTODIAN_ADDRESS.encode(), metadata: FungibleTokenMetadata::default(), }; diff --git a/engine-tests/src/test_utils/standalone/mod.rs b/engine-tests/src/utils/standalone/mod.rs similarity index 94% rename from engine-tests/src/test_utils/standalone/mod.rs rename to engine-tests/src/utils/standalone/mod.rs index 43776db5e..19d0b35e8 100644 --- a/engine-tests/src/test_utils/standalone/mod.rs +++ b/engine-tests/src/utils/standalone/mod.rs @@ -6,9 +6,9 @@ use aurora_engine::parameters::{ use aurora_engine_modexp::AuroraModExp; use aurora_engine_sdk::env::{self, Env}; use aurora_engine_transactions::legacy::{LegacyEthSignedTransaction, TransactionLegacy}; +use aurora_engine_types::borsh::BorshDeserialize; use aurora_engine_types::types::{Address, NearGas, PromiseResult, Wei}; use aurora_engine_types::{H256, U256}; -use borsh::BorshDeserialize; use engine_standalone_storage::{ sync::{ self, @@ -19,7 +19,7 @@ use engine_standalone_storage::{ use libsecp256k1::SecretKey; use tempfile::TempDir; -use crate::test_utils; +use crate::utils; pub mod mocks; pub mod storage; @@ -93,12 +93,12 @@ impl StandaloneRunner { maybe_result: Ok(None), }; self.cumulative_diff.append(outcome.diff.clone()); - test_utils::standalone::storage::commit(storage, &outcome); + storage::commit(storage, &outcome); } pub fn transfer_with_signer( &mut self, - signer: &mut test_utils::Signer, + signer: &mut utils::Signer, amount: Wei, dest: Address, ) -> Result { @@ -121,7 +121,7 @@ impl StandaloneRunner { let storage = &mut self.storage; let env = &mut self.env; env.block_height += 1; - let signed_tx = test_utils::sign_transaction(transaction, Some(self.chain_id), account); + let signed_tx = utils::sign_transaction(transaction, Some(self.chain_id), account); let transaction_bytes = rlp::encode(&signed_tx).to_vec(); Self::internal_submit_transaction( @@ -202,7 +202,7 @@ impl StandaloneRunner { env.prepaid_gas = NearGas::new(ctx.prepaid_gas); let storage = &mut self.storage; - if method_name == test_utils::SUBMIT { + if method_name == utils::SUBMIT { let transaction_bytes = &ctx.input; Self::internal_submit_transaction( transaction_bytes, @@ -212,7 +212,7 @@ impl StandaloneRunner { &mut self.cumulative_diff, promise_results, ) - } else if method_name == test_utils::SUBMIT_WITH_ARGS { + } else if method_name == utils::SUBMIT_WITH_ARGS { let submit_args = SubmitArgs::try_from_slice(&ctx.input).unwrap(); let transaction_hash = aurora_engine_sdk::keccak(&submit_args.tx_data); let mut tx_msg = @@ -225,7 +225,7 @@ impl StandaloneRunner { storage::commit(storage, &outcome); unwrap_result(outcome) - } else if method_name == test_utils::CALL { + } else if method_name == utils::CALL { let call_args = CallArgs::try_from_slice(&ctx.input).unwrap(); let transaction_hash = aurora_engine_sdk::keccak(&ctx.input); let mut tx_msg = @@ -238,7 +238,7 @@ impl StandaloneRunner { storage::commit(storage, &outcome); unwrap_result(outcome) - } else if method_name == test_utils::DEPLOY_ERC20 { + } else if method_name == utils::DEPLOY_ERC20 { let deploy_args = DeployErc20TokenArgs::try_from_slice(&ctx.input).unwrap(); let transaction_hash = aurora_engine_sdk::keccak(&ctx.input); let mut tx_msg = @@ -257,7 +257,7 @@ impl StandaloneRunner { 0, Vec::new(), )) - } else if method_name == test_utils::RESUME_PRECOMPILES { + } else if method_name == utils::RESUME_PRECOMPILES { let input = &ctx.input[..]; let call_args = PausePrecompilesCallArgs::try_from_slice(input) .expect("Unable to parse input as PausePrecompilesCallArgs"); @@ -277,7 +277,7 @@ impl StandaloneRunner { 0, Vec::new(), )) - } else if method_name == test_utils::PAUSE_PRECOMPILES { + } else if method_name == utils::PAUSE_PRECOMPILES { let input = &ctx.input[..]; let call_args = PausePrecompilesCallArgs::try_from_slice(input) .expect("Unable to parse input as PausePrecompilesCallArgs"); @@ -297,7 +297,7 @@ impl StandaloneRunner { 0, Vec::new(), )) - } else if method_name == test_utils::SET_OWNER { + } else if method_name == utils::SET_OWNER { let input = &ctx.input[..]; let call_args = SetOwnerArgs::try_from_slice(input).expect("Unable to parse input as SetOwnerArgs"); @@ -317,7 +317,7 @@ impl StandaloneRunner { 0, Vec::new(), )) - } else if method_name == test_utils::SET_UPGRADE_DELAY_BLOCKS { + } else if method_name == utils::SET_UPGRADE_DELAY_BLOCKS { let input = &ctx.input; let call_args = SetUpgradeDelayBlocksArgs::try_from_slice(input) .expect("Unable to parse input as SetUpgradeDelayBlocksArgs"); @@ -337,7 +337,7 @@ impl StandaloneRunner { 0, Vec::new(), )) - } else if method_name == test_utils::PAUSE_CONTRACT { + } else if method_name == utils::PAUSE_CONTRACT { let transaction_hash = aurora_engine_sdk::keccak(&ctx.input); let mut tx_msg = Self::template_tx_msg(storage, &env, 0, transaction_hash, promise_results); @@ -353,7 +353,7 @@ impl StandaloneRunner { 0, Vec::new(), )) - } else if method_name == test_utils::RESUME_CONTRACT { + } else if method_name == utils::RESUME_CONTRACT { let transaction_hash = aurora_engine_sdk::keccak(&ctx.input); let mut tx_msg = Self::template_tx_msg(storage, &env, 0, transaction_hash, promise_results); @@ -482,7 +482,7 @@ impl Default for StandaloneRunner { fn default() -> Self { let (storage_dir, storage) = storage::create_db(); let env = mocks::default_env(0); - let chain_id = test_utils::AuroraRunner::default().chain_id; + let chain_id = utils::AuroraRunner::default().chain_id; Self { storage_dir, storage, diff --git a/engine-tests/src/test_utils/standalone/storage.rs b/engine-tests/src/utils/standalone/storage.rs similarity index 100% rename from engine-tests/src/test_utils/standalone/storage.rs rename to engine-tests/src/utils/standalone/storage.rs diff --git a/engine-tests/src/utils/workspace.rs b/engine-tests/src/utils/workspace.rs new file mode 100644 index 000000000..58008edad --- /dev/null +++ b/engine-tests/src/utils/workspace.rs @@ -0,0 +1,131 @@ +use crate::utils; +use crate::utils::solidity::erc20::{ERC20Constructor, ERC20}; +/// Simulation tests for exit to NEAR precompile. +/// Note: `AuroraRunner` is not suitable for these tests because +/// it does not execute promises; but `aurora-workspaces` does. +use crate::utils::AuroraRunner; +use aurora_engine_types::account_id::AccountId; +use aurora_engine_types::types::Address; +use aurora_engine_types::U256; +use aurora_engine_workspace::account::Account; +use aurora_engine_workspace::{parse_near, EngineContract, RawContract}; +use serde_json::json; + +const FT_PATH: &str = "src/tests/res/fungible_token.wasm"; +const STORAGE_AMOUNT: u128 = 50_000_000_000_000_000_000_000_000; + +pub async fn deploy_engine() -> EngineContract { + let aurora_runner = AuroraRunner::default(); + aurora_engine_workspace::EngineContractBuilder::new() + .unwrap() + .with_chain_id(aurora_runner.chain_id) + .with_code(aurora_runner.code.code().to_vec()) + .with_custodian_address("d045f7e19B2488924B97F9c145b5E51D0D895A65") + .unwrap() + .with_root_balance(parse_near!("10000 N")) + .with_contract_balance(parse_near!("1000 N")) + .deploy_and_init() + .await + .unwrap() +} + +pub async fn create_sub_account( + master_account: &Account, + account: &str, + balance: u128, +) -> anyhow::Result { + master_account.create_subaccount(account, balance).await +} + +pub async fn deploy_erc20_from_nep_141( + nep_141_account: &str, + aurora: &EngineContract, +) -> anyhow::Result { + let nep141_account_id = nep_141_account.parse().unwrap(); + let result = aurora + .deploy_erc20_token(nep141_account_id) + .max_gas() + .transact() + .await + .unwrap(); + assert!(result.is_success()); + let address = result.into_value(); + let abi = ERC20Constructor::load().0.abi; + Ok(ERC20(utils::solidity::DeployedContract { abi, address })) +} + +pub async fn transfer_nep_141_to_erc_20( + nep_141: &RawContract, + erc20: &ERC20, + source: &Account, + dest: Address, + amount: u128, + aurora: &EngineContract, +) -> anyhow::Result<()> { + let result = source + .call(&nep_141.id(), "ft_transfer") + .args_json(json!({ + "receiver_id": aurora.id(), + "amount": amount.to_string(), + "memo": "null", + })) + .deposit(1) + .transact() + .await?; + assert!(result.is_success(), "{result:?}"); + let mint_tx = erc20.mint(dest, amount.into(), 0.into()); + let result = aurora + .call(erc20.0.address, U256::zero(), mint_tx.data) + .transact() + .await?; + assert!(result.is_success()); + + Ok(()) +} + +pub async fn nep_141_balance_of(nep_141: &RawContract, account_id: &AccountId) -> u128 { + nep_141 + .view("ft_balance_of") + .args_json(json!({ "account_id": account_id })) + .await + .unwrap() + .json::() + .map(|s| s.parse().unwrap()) + .unwrap() +} + +/// Deploys the standard FT implementation: +/// `https://github.com/near/near-sdk-rs/blob/master/examples/fungible-token/ft/src/lib.rs` +pub async fn deploy_nep_141( + nep_141_account: &Account, + token_owner: &Account, + amount: u128, + aurora: &EngineContract, +) -> anyhow::Result { + let contract_bytes = std::fs::read(FT_PATH)?; + let nep141 = nep_141_account.deploy(&contract_bytes).await?; + let result = aurora + .root() + .call(&nep141.id(), "new_default_meta") + .args_json(json!({ + "owner_id": token_owner.id(), + "total_supply": format!("{amount}"), + })) + .transact() + .await?; + assert!(result.is_success(), "{result:?}"); + + // Need to register Aurora contract so that it can receive tokens + let result = aurora + .root() + .call(&nep141.id(), "storage_deposit") + .args_json(json!({ + "account_id": aurora.id(), + })) + .deposit(STORAGE_AMOUNT) + .transact() + .await?; + assert!(result.is_success()); + + Ok(nep141) +} diff --git a/engine-transactions/src/legacy.rs b/engine-transactions/src/legacy.rs index 00d2e8585..971d5f165 100644 --- a/engine-transactions/src/legacy.rs +++ b/engine-transactions/src/legacy.rs @@ -5,7 +5,7 @@ use aurora_engine_types::types::{Address, Wei}; use aurora_engine_types::{Vec, U256}; use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; -#[derive(Debug, Eq, PartialEq, Clone)] +#[derive(Debug, Default, Eq, PartialEq, Clone)] pub struct TransactionLegacy { /// A monotonically increasing transaction counter for this sender pub nonce: U256, diff --git a/engine-types/src/parameters/mod.rs b/engine-types/src/parameters/mod.rs index 76d19a672..02d74b39e 100644 --- a/engine-types/src/parameters/mod.rs +++ b/engine-types/src/parameters/mod.rs @@ -3,3 +3,4 @@ pub use promise::*; pub mod connector; pub mod engine; pub mod promise; +pub mod xcc; diff --git a/engine-types/src/parameters/xcc.rs b/engine-types/src/parameters/xcc.rs new file mode 100644 index 000000000..20a82093b --- /dev/null +++ b/engine-types/src/parameters/xcc.rs @@ -0,0 +1,28 @@ +use crate::account_id::AccountId; +use crate::borsh::{self, BorshDeserialize, BorshSerialize}; +use crate::types::Address; + +#[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize)] +pub struct AddressVersionUpdateArgs { + pub address: Address, + pub version: CodeVersion, +} + +#[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize)] +pub struct FundXccArgs { + pub target: Address, + pub wnear_account_id: Option, +} + +/// Type wrapper for version of router contracts. +#[derive( + Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, BorshDeserialize, BorshSerialize, +)] +pub struct CodeVersion(pub u32); + +impl CodeVersion { + #[must_use] + pub const fn increment(self) -> Self { + Self(self.0 + 1) + } +} diff --git a/engine-workspace/Cargo.toml b/engine-workspace/Cargo.toml new file mode 100644 index 000000000..d002d4def --- /dev/null +++ b/engine-workspace/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "aurora-engine-workspace" +version = "0.1.0" +description = "Environment for testing Aurora EVM contract" +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +publish.workspace = true +autobenches = false + +[dependencies] +aurora-engine-types = { workspace = true, features = ["borsh-compat", "impl-serde", "std"] } +anyhow.workspace = true +near-sdk.workspace = true +near-units.workspace = true +serde.workspace = true +serde_json.workspace = true +workspaces.workspace = true +tokio = { workspace = true, features = [ "time" ] } + +[dev-dependencies] +hex.workspace = true +lazy_static.workspace = true diff --git a/engine-workspace/README.md b/engine-workspace/README.md new file mode 100644 index 000000000..e3138fb20 --- /dev/null +++ b/engine-workspace/README.md @@ -0,0 +1,2 @@ +# Environment for testing Aurora EVM + diff --git a/engine-workspace/src/account.rs b/engine-workspace/src/account.rs new file mode 100644 index 000000000..8cdaba6a3 --- /dev/null +++ b/engine-workspace/src/account.rs @@ -0,0 +1,51 @@ +use crate::transaction::{CallTransaction, ViewTransaction}; +use aurora_engine_types::account_id::AccountId; +use std::str::FromStr; + +use crate::contract::RawContract; +pub use near_units::parse_near; + +#[derive(Debug, Clone)] +pub struct Account { + inner: workspaces::Account, +} + +impl Account { + pub(crate) fn from_inner(inner: workspaces::Account) -> Self { + Self { inner } + } + + pub fn call>(&self, contract_id: &AccountId, function: F) -> CallTransaction { + let contract_id = workspaces::AccountId::from_str(contract_id.as_ref()).unwrap(); + let transaction = self.inner.call(&contract_id, function.as_ref()); + + CallTransaction::new(transaction) + } + + pub fn view>(&self, contract_id: &AccountId, function: F) -> ViewTransaction { + let contract_id = workspaces::AccountId::from_str(contract_id.as_ref()).unwrap(); + let transaction = self.inner.view(&contract_id, function.as_ref()); + + ViewTransaction::new(transaction) + } + + pub async fn deploy(&self, wasm: &[u8]) -> anyhow::Result { + let contract = self.inner.deploy(wasm).await?.into_result()?; + Ok(RawContract::from_contract(contract)) + } + + pub fn id(&self) -> AccountId { + self.inner.id().as_str().parse().unwrap() + } + + pub async fn create_subaccount(&self, name: &str, balance: u128) -> anyhow::Result { + self.inner + .create_subaccount(name) + .initial_balance(balance) + .transact() + .await? + .into_result() + .map(|inner| Account { inner }) + .map_err(Into::into) + } +} diff --git a/engine-workspace/src/contract.rs b/engine-workspace/src/contract.rs new file mode 100644 index 000000000..3c0366d35 --- /dev/null +++ b/engine-workspace/src/contract.rs @@ -0,0 +1,393 @@ +use crate::account::Account; +use crate::node::Node; +use crate::operation::{ + CallCall, CallDeployCode, CallDeployErc20Token, CallDeployUpgrade, CallDeposit, + CallFactorySetWNearAddress, CallFactoryUpdate, CallFactoryUpdateAddressVersion, + CallFtOnTransfer, CallFtTransfer, CallFtTransferCall, CallFundXccSubAccount, CallMintAccount, + CallNew, CallNewEthConnector, CallPausePrecompiles, CallRefundOnError, CallRegisterRelayer, + CallResumePrecompiles, CallSetEthConnectorContractData, CallSetPausedFlags, CallStageUpgrade, + CallStateMigration, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, CallSubmit, + CallWithdraw, ViewAccountsCounter, ViewBalance, ViewBlockHash, ViewBridgeProver, ViewChainId, + ViewCode, ViewErc20FromNep141, ViewFtBalanceOf, ViewFtBalanceOfEth, ViewFtMetadata, + ViewFtTotalEthSupplyOnAurora, ViewFtTotalEthSupplyOnNear, ViewFtTotalSupply, ViewIsUsedProof, + ViewNep141FromErc20, ViewNonce, ViewOwner, ViewPausedFlags, ViewPausedPrecompiles, + ViewStorageAt, ViewStorageBalanceOf, ViewUpgradeIndex, ViewVersion, ViewView, +}; +use crate::transaction::{CallTransaction, ViewTransaction}; +use aurora_engine_types::account_id::AccountId; +use aurora_engine_types::parameters::connector::{FungibleTokenMetadata, Proof}; +use aurora_engine_types::parameters::engine::{ + CallArgs, FunctionCallArgsV2, NewCallArgs, NewCallArgsV2, PausedMask, +}; +use aurora_engine_types::parameters::xcc::FundXccArgs; +use aurora_engine_types::types::{Address, RawU256, WeiU256}; +use aurora_engine_types::{H256, U256}; +use near_sdk::json_types::U128; +use serde_json::json; + +#[derive(Debug, Clone)] +pub struct EngineContract { + contract: RawContract, + pub node: Node, +} + +impl EngineContract { + pub fn as_raw_contract(&self) -> &RawContract { + &self.contract + } + + pub fn id(&self) -> AccountId { + self.contract.id() + } + + pub fn root(&self) -> Account { + self.node.root() + } +} + +impl From<(RawContract, Node)> for EngineContract { + fn from((contract, node): (RawContract, Node)) -> Self { + Self { contract, node } + } +} + +/// Callable functions implementation. +impl EngineContract { + #[allow(clippy::new_ret_no_self)] + pub fn new( + &self, + chain_id: RawU256, + owner_id: AccountId, + upgrade_delay_blocks: u64, + ) -> CallNew { + let args = NewCallArgs::V2(NewCallArgsV2 { + chain_id, + owner_id, + upgrade_delay_blocks, + }); + + CallNew::call(&self.contract).args_borsh(args) + } + + pub fn new_eth_connector( + &self, + prover_account: AccountId, + custodian_address: String, + metadata: FungibleTokenMetadata, + ) -> CallNewEthConnector { + CallNewEthConnector::call(&self.contract).args_borsh(( + prover_account, + custodian_address, + metadata, + )) + } + + pub fn ft_transfer( + &self, + receiver_id: &AccountId, + amount: U128, + memo: Option, + ) -> CallFtTransfer { + CallFtTransfer::call(&self.contract) + .args_json(json!({ "receiver_id": receiver_id, "amount": amount, "memo": memo })) + } + + pub fn ft_transfer_call( + &self, + receiver_id: &AccountId, + amount: U128, + memo: Option, + msg: String, + ) -> CallFtTransferCall { + CallFtTransferCall::call(&self.contract).args_json(json!({ + "receiver_id": receiver_id, + "amount": amount, + "memo": memo, + "msg": msg, + })) + } + + pub fn storage_deposit( + &self, + account_id: Option, + registration_only: Option, + ) -> CallStorageDeposit { + CallStorageDeposit::call(&self.contract) + .args_json(json!({ "account_id": account_id, "registration_only": registration_only})) + } + + pub fn storage_withdraw(&self, amount: Option) -> CallStorageWithdraw { + CallStorageWithdraw::call(&self.contract).args_json(json!({ "amount": amount })) + } + + pub fn storage_unregister(&self, force: Option) -> CallStorageUnregister { + CallStorageUnregister::call(&self.contract).args_json(json!({ "force": force })) + } + + pub fn withdraw(&self, recipient_address: Address, amount: u128) -> CallWithdraw { + CallWithdraw::call(&self.contract).args_borsh((recipient_address, amount)) + } + + pub fn deposit(&self, raw_proof: Proof) -> CallDeposit { + CallDeposit::call(&self.contract).args_borsh(raw_proof) + } + + pub fn set_eth_connector_contract_data( + &self, + prover_account: AccountId, + eth_custodian_address: String, + metadata: FungibleTokenMetadata, + ) -> CallSetEthConnectorContractData { + CallSetEthConnectorContractData::call(&self.contract).args_borsh(( + prover_account, + eth_custodian_address, + metadata, + )) + } + + pub fn factory_update_address_version( + &self, + address: Address, + version: u32, + ) -> CallFactoryUpdateAddressVersion { + CallFactoryUpdateAddressVersion::call(&self.contract).args_borsh((address, version)) + } + + pub fn refund_on_error( + &self, + recipient_address: Address, + erc20_address: Option
, + amount: U256, + ) -> CallRefundOnError { + CallRefundOnError::call(&self.contract).args_borsh(( + recipient_address, + erc20_address, + amount.0, + )) + } + + pub fn deploy_code(&self, code: Vec) -> CallDeployCode { + CallDeployCode::call(&self.contract).args(code) + } + + pub fn deploy_erc20_token(&self, account_id: AccountId) -> CallDeployErc20Token { + CallDeployErc20Token::call(&self.contract).args_borsh(account_id) + } + + pub fn call(&self, contract: Address, amount: U256, input: Vec) -> CallCall { + let value = WeiU256::from(amount); + let args = CallArgs::V2(FunctionCallArgsV2 { + contract, + value, + input, + }); + CallCall::call(&self.contract).args_borsh(args) + } + + pub fn submit(&self, input: Vec) -> CallSubmit { + CallSubmit::call(&self.contract).args(input) + } + + pub fn register_relayer(&self, address: Address) -> CallRegisterRelayer { + CallRegisterRelayer::call(&self.contract).args_borsh(address) + } + + pub fn ft_on_transfer( + &self, + sender_id: AccountId, + amount: U128, + message: String, + ) -> CallFtOnTransfer { + CallFtOnTransfer::call(&self.contract).args_json(json!({ + "sender_id": sender_id, + "amount": amount, + "message": message + })) + } + + pub fn factory_update(&self, bytes: Vec) -> CallFactoryUpdate { + CallFactoryUpdate::call(&self.contract).args(bytes) + } + + pub fn fund_xcc_sub_account( + &self, + target: Address, + wnear_account_id: Option, + ) -> CallFundXccSubAccount { + let args = FundXccArgs { + target, + wnear_account_id, + }; + CallFundXccSubAccount::call(&self.contract).args_borsh(args) + } + + pub fn factory_set_wnear_address(&self, address: Address) -> CallFactorySetWNearAddress { + CallFactorySetWNearAddress::call(&self.contract).args_borsh(address) + } + + pub fn stage_upgrade(&self, bytes: Vec) -> CallStageUpgrade { + CallStageUpgrade::call(&self.contract).args(bytes) + } + + pub fn deploy_upgrade(&self) -> CallDeployUpgrade { + CallDeployUpgrade::call(&self.contract) + } + + pub fn pause_precompiles(&self, paused_mask: u32) -> CallPausePrecompiles { + CallPausePrecompiles::call(&self.contract).args_borsh(paused_mask) + } + + pub fn resume_precompiles(&self, paused_mask: u32) -> CallResumePrecompiles { + CallResumePrecompiles::call(&self.contract).args_borsh(paused_mask) + } + + pub fn state_migration(&self) -> CallStateMigration { + CallStateMigration::call(&self.contract) + } + + pub fn mint_account( + &self, + address: Address, + init_nonce: u64, + init_balance: u64, + ) -> CallMintAccount { + CallMintAccount::call(&self.contract).args_borsh((address, init_nonce, init_balance)) + } + + pub fn set_paused_flags(&self, flags: PausedMask) -> CallSetPausedFlags { + CallSetPausedFlags::call(&self.contract).args_borsh(flags) + } +} + +/// View functions +impl EngineContract { + pub fn ft_total_supply(&self) -> ViewFtTotalSupply { + ViewFtTotalSupply::view(&self.contract) + } + + pub fn ft_balance_of(&self, account_id: &AccountId) -> ViewFtBalanceOf { + ViewFtBalanceOf::view(&self.contract).args_json(json!({ "account_id": account_id })) + } + + pub fn storage_balance_of(&self, account_id: &AccountId) -> ViewStorageBalanceOf { + ViewStorageBalanceOf::view(&self.contract).args_json(json!({ "account_id": account_id })) + } + + pub fn ft_metadata(&self) -> ViewFtMetadata { + ViewFtMetadata::view(&self.contract) + } + + pub fn get_version(&self) -> ViewVersion { + ViewVersion::view(&self.contract) + } + + pub fn get_owner(&self) -> ViewOwner { + ViewOwner::view(&self.contract) + } + + pub fn get_bridge_prover(&self) -> ViewBridgeProver { + ViewBridgeProver::view(&self.contract) + } + + pub fn get_chain_id(&self) -> ViewChainId { + ViewChainId::view(&self.contract) + } + + pub fn get_upgrade_index(&self) -> ViewUpgradeIndex { + ViewUpgradeIndex::view(&self.contract) + } + + pub fn get_paused_precompiles(&self) -> ViewPausedPrecompiles { + ViewPausedPrecompiles::view(&self.contract) + } + + pub fn get_block_hash(&self, block_height: u64) -> ViewBlockHash { + ViewBlockHash::view(&self.contract).args_borsh(block_height) + } + + pub fn get_code(&self, address: Address) -> ViewCode { + ViewCode::view(&self.contract).args_borsh(address) + } + + pub fn get_balance(&self, address: Address) -> ViewBalance { + ViewBalance::view(&self.contract).args(address.as_bytes().to_vec()) + } + + pub fn get_nonce(&self, address: Address) -> ViewNonce { + ViewNonce::view(&self.contract).args(address.as_bytes().to_vec()) + } + + pub fn get_storage_at(&self, address: Address, key: H256) -> ViewStorageAt { + let raw_key = >::into(key); + ViewStorageAt::view(&self.contract).args_borsh((address, raw_key)) + } + + pub fn get_view( + &self, + sender: Address, + address: Address, + amount: U256, + input: Vec, + ) -> ViewView { + let mut raw_amount = [0u8; 32]; + amount.to_big_endian(&mut raw_amount); + ViewView::view(&self.contract).args_borsh((sender, address, raw_amount, input)) + } + + pub fn is_used_proof(&self, proof: Proof) -> ViewIsUsedProof { + ViewIsUsedProof::view(&self.contract).args_borsh(proof) + } + + pub fn ft_total_eth_supply_on_aurora(&self) -> ViewFtTotalEthSupplyOnAurora { + ViewFtTotalEthSupplyOnAurora::view(&self.contract) + } + + pub fn ft_total_eth_supply_on_near(&self) -> ViewFtTotalEthSupplyOnNear { + ViewFtTotalEthSupplyOnNear::view(&self.contract) + } + + pub fn ft_balance_of_eth(&self, address: Address) -> ViewFtBalanceOfEth { + ViewFtBalanceOfEth::view(&self.contract).args_borsh(address) + } + + pub fn get_erc20_from_nep141(&self, account: AccountId) -> ViewErc20FromNep141 { + ViewErc20FromNep141::view(&self.contract).args_borsh(account) + } + + pub fn get_nep141_from_erc20(&self, address: Address) -> ViewNep141FromErc20 { + ViewNep141FromErc20::view(&self.contract).args_borsh(address) + } + + pub fn get_paused_flags(&self) -> ViewPausedFlags { + ViewPausedFlags::view(&self.contract) + } + + pub fn get_accounts_counter(&self) -> ViewAccountsCounter { + ViewAccountsCounter::view(&self.contract) + } +} + +#[derive(Debug, Clone)] +pub struct RawContract { + inner: workspaces::Contract, +} + +impl RawContract { + pub fn from_contract(contract: workspaces::Contract) -> Self { + Self { inner: contract } + } + + pub fn call>(&self, function: F) -> CallTransaction { + let call_tx = self.inner.call(function.as_ref()); + CallTransaction::new(call_tx) + } + + pub fn view>(&self, function: F) -> ViewTransaction { + let view_tx = self.inner.view(function.as_ref()); + ViewTransaction::new(view_tx) + } + + pub fn id(&self) -> AccountId { + self.inner.id().as_str().parse().unwrap() + } +} diff --git a/engine-workspace/src/lib.rs b/engine-workspace/src/lib.rs new file mode 100644 index 000000000..c1a7303bb --- /dev/null +++ b/engine-workspace/src/lib.rs @@ -0,0 +1,164 @@ +use aurora_engine_types::account_id::AccountId; +use aurora_engine_types::parameters::connector::FungibleTokenMetadata; +use aurora_engine_types::types::address::Address; +use aurora_engine_types::U256; + +use crate::node::Node; + +pub use crate::contract::{EngineContract, RawContract}; +pub use near_units::parse_near; + +pub mod account; +pub mod contract; +pub mod macros; +pub mod node; +pub mod operation; +pub mod result; +pub mod transaction; + +pub mod types { + pub use workspaces::result::ExecutionOutcome; +} + +const AURORA_LOCAL_CHAIN_ID: u64 = 1313161556; +const OWNER_ACCOUNT_ID: &str = "aurora.root"; +const PROVER_ACCOUNT_ID: &str = "prover.root"; +const ROOT_BALANCE: u128 = parse_near!("400 N"); +const CONTRACT_BALANCE: u128 = parse_near!("200 N"); + +#[derive(Debug)] +pub struct EngineContractBuilder { + code: Option>, + chain_id: [u8; 32], + owner_id: AccountId, + prover_id: AccountId, + custodian_address: Address, + upgrade_delay_blocks: u64, + root_balance: u128, + contract_balance: u128, + ft_metadata: FungibleTokenMetadata, +} + +impl EngineContractBuilder { + pub fn new() -> anyhow::Result { + Ok(Self { + code: None, + chain_id: into_chain_id(AURORA_LOCAL_CHAIN_ID), + owner_id: OWNER_ACCOUNT_ID.parse().unwrap(), + prover_id: PROVER_ACCOUNT_ID.parse().unwrap(), + custodian_address: Address::zero(), + upgrade_delay_blocks: 1, + root_balance: ROOT_BALANCE, + contract_balance: CONTRACT_BALANCE, + ft_metadata: FungibleTokenMetadata::default(), + }) + } + + pub fn with_code(mut self, code: Vec) -> Self { + self.code = Some(code); + self + } + + pub fn with_chain_id(mut self, chain_id: u64) -> Self { + self.chain_id = into_chain_id(chain_id); + self + } + + pub fn with_owner_id(mut self, owner_id: &str) -> anyhow::Result { + self.owner_id = owner_id + .parse() + .map_err(|e| anyhow::anyhow!("Parse account_id error: {e}"))?; + Ok(self) + } + + pub fn with_prover_id(mut self, prover_id: &str) -> anyhow::Result { + self.prover_id = prover_id + .parse() + .map_err(|e| anyhow::anyhow!("Parse account_id error: {e}"))?; + Ok(self) + } + + pub fn with_custodian_address(mut self, address: &str) -> anyhow::Result { + self.custodian_address = Address::decode(address).map_err(|e| anyhow::anyhow!({ e }))?; + Ok(self) + } + + pub fn with_upgrade_delay_blocks(mut self, upgrade_delay_blocks: u64) -> Self { + self.upgrade_delay_blocks = upgrade_delay_blocks; + self + } + + pub fn with_ft_metadata(mut self, ft_metadata: FungibleTokenMetadata) -> Self { + self.ft_metadata = ft_metadata; + self + } + + pub fn with_root_balance(mut self, balance: u128) -> Self { + self.root_balance = balance; + self + } + + pub fn with_contract_balance(mut self, balance: u128) -> Self { + self.contract_balance = balance; + self + } + + pub async fn deploy_and_init(self) -> anyhow::Result { + let owner_id = self.owner_id.as_ref(); + let (owner, root) = owner_id.split_once('.').unwrap_or((owner_id, owner_id)); + let node = Node::new(root, self.root_balance).await?; + let owner_acc = if owner != root { + node.root() + .create_subaccount(owner, self.contract_balance) + .await? + } else { + node.root() + }; + let contract = owner_acc + .deploy(&self.code.expect("WASM wasn't set")) + .await?; + let engine: EngineContract = (contract, node).into(); + + engine + .new(self.chain_id, self.owner_id, self.upgrade_delay_blocks) + .transact() + .await + .map_err(|e| anyhow::anyhow!("Error while initialize aurora contract: {e}"))?; + + engine + .new_eth_connector( + self.prover_id, + self.custodian_address.encode(), + self.ft_metadata, + ) + .transact() + .await + .map_err(|e| anyhow::anyhow!("Error while initialize eth-connector: {e}"))?; + + Ok(engine) + } +} + +fn into_chain_id(value: u64) -> [u8; 32] { + let chain_id = U256::from(value); + let mut result = [0; 32]; + chain_id.to_big_endian(&mut result); + + result +} + +#[tokio::test] +async fn test_creating_aurora_contract() { + let code = std::fs::read("../bin/aurora-mainnet-test.wasm").unwrap(); + let contract = EngineContractBuilder::new() + .unwrap() + .with_owner_id("aurora.test.near") + .unwrap() + .with_code(code) + .deploy_and_init() + .await + .unwrap(); + + let chain_id = contract.get_chain_id().await.unwrap().result; + assert_eq!(chain_id, U256::from(into_chain_id(AURORA_LOCAL_CHAIN_ID))); +} diff --git a/engine-workspace/src/macros.rs b/engine-workspace/src/macros.rs new file mode 100644 index 000000000..a66c67491 --- /dev/null +++ b/engine-workspace/src/macros.rs @@ -0,0 +1,111 @@ +#[macro_export] +macro_rules! impl_view_return { + ($(($name:ident => $return:ty, $fn_name:expr, $deserialize_fn:ident)),* $(,)?) => { + use aurora_engine_types::borsh; + $(pub struct $name<'a>(ViewTransaction<'a>); + impl<'a> $name<'a> { + pub(crate) fn view(contract: &'a RawContract) -> Self { + Self(contract.view(&$fn_name)) + } + pub fn args(mut self, args: Vec) -> Self { + self.0 = self.0.args(args); + self + } + pub fn args_json(mut self, args: S) -> Self { + self.0 = self.0.args_json(args); + self + } + pub fn args_borsh(mut self, args: B) -> Self { + self.0 = self.0.args_borsh(args); + self + } + } + + impl<'a> std::future::IntoFuture for $name<'a> { + type Output = anyhow::Result>; + type IntoFuture = workspaces::rpc::BoxFuture<'a, Self::Output>; + + fn into_future(self) -> Self::IntoFuture { + Box::pin(async { ViewResult::$deserialize_fn(self.0.await?) }.into_future()) + } + })* + }; +} + +#[macro_export] +macro_rules! impl_call_return { + ($(($name:ident => $return:ty, $fn_name:expr, $deserialize_fn:ident)),* $(,)?) => { + $(pub struct $name<'a>(CallTransaction<'a>); + impl<'a> $name<'a> { + pub(crate) fn call(contract: &'a RawContract) -> Self { + Self(contract.call(&$fn_name)) + } + pub fn gas(mut self, gas: u64) -> Self { + self.0 = self.0.gas(gas); + self + } + pub fn max_gas(mut self) -> Self { + self.0 = self.0.max_gas(); + self + } + pub fn deposit(mut self, deposit: u128) -> Self { + self.0 = self.0.deposit(deposit); + self + } + pub fn args(mut self, args: Vec) -> Self { + self.0 = self.0.args(args); + self + } + pub fn args_json(mut self, args: S) -> Self { + self.0 = self.0.args_json(args); + self + } + pub fn args_borsh(mut self, args: B) -> Self { + self.0 = self.0.args_borsh(args); + self + } + pub async fn transact(self) -> anyhow::Result> { + ExecutionResult::$deserialize_fn(self.0.transact().await?) + } + })* + }; + ($(($name:ident, $fn_name:expr)),* $(,)?) => { + $(pub struct $name<'a>(CallTransaction<'a>); + impl<'a> $name<'a> { + pub(crate) fn call(contract: &'a RawContract) -> Self { + Self(contract.call(&$fn_name)) + } + pub fn gas(mut self, gas: u64) -> Self { + self.0 = self.0.gas(gas); + self + } + pub fn max_gas(mut self) -> Self { + self.0 = self.0.max_gas(); + self + } + pub fn deposit(mut self, deposit: u128) -> Self { + self.0 = self.0.deposit(deposit); + self + } + pub fn args(mut self, args: Vec) -> Self { + self.0 = self.0.args(args); + self + } + pub fn args_json(mut self, args: S) -> Self { + self.0 = self.0.args_json(args); + self + + } + pub fn args_borsh(mut self, args: B) -> Self { + self.0 = self.0.args_borsh(args); + self + } + pub async fn transact(self) -> anyhow::Result> { + let result = self.0.transact().await?; + let success = result.is_success(); + let inner = result.into_result()?; + Ok(ExecutionResult::new(inner, (), success)) + } + })* + }; +} diff --git a/engine-workspace/src/node.rs b/engine-workspace/src/node.rs new file mode 100644 index 000000000..194bb603c --- /dev/null +++ b/engine-workspace/src/node.rs @@ -0,0 +1,104 @@ +use aurora_engine_types::account_id::AccountId; +use std::str::FromStr; +use std::time::Duration; +use tokio::time::Instant; +use workspaces::network::{NetworkClient, Sandbox}; +use workspaces::types::{KeyType, SecretKey}; +use workspaces::Worker; + +use crate::account::Account; + +#[derive(Debug, Clone)] +pub struct Node { + root: workspaces::Account, + worker: Worker, +} + +impl Node { + pub async fn new(root: &str, root_balance: u128) -> anyhow::Result { + let worker = workspaces::sandbox().await?; + let root = Self::create_root_account(&worker, root, root_balance).await?; + + Ok(Self { root, worker }) + } + + pub fn root(&self) -> Account { + Account::from_inner(self.root.clone()) + } + + pub async fn get_balance(&self, account_id: &AccountId) -> anyhow::Result { + let account_id = workspaces::AccountId::from_str(account_id.as_ref())?; + + self.worker + .view_account(&account_id) + .await + .map(|d| d.balance) + .map_err(Into::into) + } + + async fn create_root_account( + worker: &Worker, + root_acc_name: &str, + balance: u128, + ) -> anyhow::Result { + use workspaces::AccessKey; + + if root_acc_name == "test.near" { + return Ok(worker.root_account()?); + } + + let registrar = if root_acc_name.ends_with("near") { + worker + .import_contract(&"near".parse()?, worker) + .transact() + .await? + } else { + let testnet = workspaces::testnet() + .await + .map_err(|err| anyhow::anyhow!("Failed init testnet: {:?}", err))?; + let registrar = "registrar".parse()?; + worker + .import_contract(®istrar, &testnet) + .transact() + .await? + }; + + Self::waiting_account_creation(worker, registrar.id()).await?; + + let sk = SecretKey::from_seed(KeyType::ED25519, "registrar"); + let root = root_acc_name.parse()?; + registrar + .as_account() + .batch(&root) + .create_account() + .add_key(sk.public_key(), AccessKey::full_access()) + .transfer(balance) + .transact() + .await? + .into_result()?; + + Ok(workspaces::Account::from_secret_key(root, sk, worker)) + } + + /// Waiting for the account creation + async fn waiting_account_creation( + worker: &Worker, + account_id: &workspaces::AccountId, + ) -> anyhow::Result<()> { + let timer = Instant::now(); + // Try to get account within 30 secs + for _ in 0..60 { + if worker.view_account(account_id).await.is_err() { + tokio::time::sleep(Duration::from_millis(500)).await; + } else { + return Ok(()); + } + } + + anyhow::bail!( + "Account `{}` was not created during {} seconds", + account_id, + timer.elapsed().as_secs_f32() + ) + } +} diff --git a/engine-workspace/src/operation.rs b/engine-workspace/src/operation.rs new file mode 100644 index 000000000..69374dc93 --- /dev/null +++ b/engine-workspace/src/operation.rs @@ -0,0 +1,206 @@ +use aurora_engine_types::account_id::AccountId; +use aurora_engine_types::parameters::connector::{FungibleTokenMetadata, WithdrawResult}; +use aurora_engine_types::parameters::engine::{StorageBalance, SubmitResult, TransactionStatus}; +use aurora_engine_types::types::Address; +use aurora_engine_types::{H256, U256}; +use near_sdk::json_types::U128; +use near_sdk::PromiseOrValue; + +use crate::contract::RawContract; +use crate::result::{ExecutionResult, ViewResult}; +use crate::transaction::{CallTransaction, ViewTransaction}; +use crate::{impl_call_return, impl_view_return}; + +impl_call_return![ + (CallNew, Call::New), + (CallNewEthConnector, Call::NewEthConnector), + (CallFtTransfer, Call::FtTransfer), + (CallDeposit, Call::Deposit), + ( + CallSetEthConnectorContractData, + Call::SetEthConnectorContractData + ), + ( + CallFactoryUpdateAddressVersion, + Call::FactoryUpdateAddressVersion + ), + (CallRegisterRelayer, Call::RegisterRelayer), + (CallRefundOnError, Call::RefundOnError), + (CallFactoryUpdate, Call::FactoryUpdate), + (CallFundXccSubAccount, Call::FundXccSubAccount), + (CallFactorySetWNearAddress, Call::FactorySetWNearAddress), + (CallDeployUpgrade, Call::DeployUpgrade), + (CallResumePrecompiles, Call::ResumePrecompiles), + (CallPausePrecompiles, Call::PausePrecompiles), + (CallStageUpgrade, Call::StageUpgrade), + (CallStateMigration, Call::StateMigration), + (CallMintAccount, Call::MintAccount), + (CallSetPausedFlags, Call::SetPausedFlags), +]; + +impl_call_return![ + (CallFtTransferCall => PromiseOrValue, Call::FtTransferCall, try_from), + (CallStorageDeposit => StorageBalance, Call::StorageDeposit, json), + (CallStorageUnregister => bool, Call::StorageUnregister, json), + (CallStorageWithdraw => StorageBalance, Call::StorageWithdraw, json), + (CallWithdraw => WithdrawResult, Call::Withdraw, borsh), + (CallDeployCode => SubmitResult, Call::DeployCode, borsh), + (CallDeployErc20Token => Address, Call::DeployErc20Token, borsh_address), + (CallCall => SubmitResult, Call::Call, borsh), + (CallSubmit => SubmitResult, Call::Submit, borsh), + (CallFtOnTransfer => U128, Call::FtOnTransfer, json), +]; + +impl_view_return![ + (ViewFtTotalSupply => U128, View::FtTotalSupply, json), + (ViewFtBalanceOf => U128, View::FtBalanceOf, json), + (ViewStorageBalanceOf => StorageBalance, View::StorageBalanceOf, json), + (ViewFtMetadata => FungibleTokenMetadata, View::FtMetadata, json), + (ViewVersion => String, View::Version, borsh), + (ViewOwner => AccountId, View::Owner, borsh), + (ViewBridgeProver => AccountId, View::BridgeProver, borsh), + (ViewChainId => U256, View::ChainId, borsh_U256), + (ViewUpgradeIndex => u64, View::UpgradeIndex, borsh), + (ViewPausedPrecompiles => u32, View::PausedPrecompiles, borsh), + (ViewBlockHash => H256, View::BlockHash, borsh_H256), + (ViewCode => Vec, View::Code, vec), + (ViewBalance => U256, View::Balance, borsh_U256), + (ViewNonce => U256, View::Nonce, borsh_U256), + (ViewStorageAt => H256, View::StorageAt, borsh_H256), + (ViewView => TransactionStatus, View::View, borsh), + (ViewIsUsedProof => bool, View::IsUsedProof, borsh), + (ViewFtTotalEthSupplyOnAurora => U128, View::FtTotalEthSupplyOnAurora, json), + (ViewFtTotalEthSupplyOnNear => U128, View::FtTotalEthSupplyOnNear, json), + (ViewFtBalanceOfEth => U128, View::FtBalanceOfEth, json), + (ViewErc20FromNep141 => Address, View::Erc20FromNep141, borsh), + (ViewNep141FromErc20 => AccountId, View::Nep141FromErc20, borsh), + (ViewPausedFlags => u8, View::PausedFlags, borsh), + (ViewAccountsCounter => u64, View::AccountsCounter, borsh) +]; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[allow(clippy::enum_variant_names)] +pub(crate) enum Call { + New, + NewEthConnector, + DeployCode, + DeployErc20Token, + Call, + Submit, + RegisterRelayer, + FtOnTransfer, + Withdraw, + Deposit, + FtTransfer, + FtTransferCall, + StorageDeposit, + StorageUnregister, + StorageWithdraw, + PausePrecompiles, + StageUpgrade, + DeployUpgrade, + StateMigration, + ResumePrecompiles, + FactoryUpdate, + FundXccSubAccount, + FactorySetWNearAddress, + SetEthConnectorContractData, + FactoryUpdateAddressVersion, + RefundOnError, + MintAccount, + SetPausedFlags, +} + +impl AsRef for Call { + fn as_ref(&self) -> &str { + match self { + Call::New => "new", + Call::NewEthConnector => "new_eth_connector", + Call::DeployCode => "deploy_code", + Call::DeployErc20Token => "deploy_erc20_token", + Call::Call => "call", + Call::Submit => "submit", + Call::RegisterRelayer => "register_relayer", + Call::FtOnTransfer => "ft_on_transfer", + Call::Withdraw => "withdraw", + Call::Deposit => "deposit", + Call::FtTransfer => "ft_transfer", + Call::FtTransferCall => "ft_transfer_call", + Call::StorageDeposit => "storage_deposit", + Call::StorageUnregister => "storage_unregister", + Call::StorageWithdraw => "storage_withdraw", + Call::PausePrecompiles => "pause_precompiles", + Call::StageUpgrade => "stage_upgrade", + Call::DeployUpgrade => "deploy_upgrade", + Call::StateMigration => "state_migration", + Call::ResumePrecompiles => "resume_precompiles", + Call::FactoryUpdate => "factory_update", + Call::FundXccSubAccount => "fund_xcc_sub_account", + Call::FactorySetWNearAddress => "factory_set_wnear_address", + Call::SetEthConnectorContractData => "set_eth_connector_contract_data", + Call::FactoryUpdateAddressVersion => "factory_update_address_version", + Call::RefundOnError => "refund_on_error", + Call::MintAccount => "mint_account", + Call::SetPausedFlags => "set_paused_flags", + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum View { + Version, + Owner, + BridgeProver, + ChainId, + UpgradeIndex, + PausedPrecompiles, + BlockHash, + Code, + Balance, + Nonce, + StorageAt, + View, + IsUsedProof, + FtTotalSupply, + FtBalanceOf, + FtBalanceOfEth, + FtTotalEthSupplyOnAurora, + FtTotalEthSupplyOnNear, + FtMetadata, + StorageBalanceOf, + PausedFlags, + Erc20FromNep141, + Nep141FromErc20, + AccountsCounter, +} + +impl AsRef for View { + fn as_ref(&self) -> &str { + match self { + View::Version => "get_version", + View::Owner => "get_owner", + View::BridgeProver => "get_bridge_prover", + View::ChainId => "get_chain_id", + View::UpgradeIndex => "get_upgrade_index", + View::PausedPrecompiles => "get_paused_precompiles", + View::BlockHash => "get_block_hash", + View::Code => "get_code", + View::Balance => "get_balance", + View::Nonce => "get_nonce", + View::StorageAt => "get_storage_at", + View::View => "get_view", + View::IsUsedProof => "is_used_proof", + View::FtTotalSupply => "ft_total_supply", + View::FtBalanceOf => "ft_balance_of", + View::FtBalanceOfEth => "ft_balance_of_eth", + View::FtTotalEthSupplyOnAurora => "ft_total_eth_supply_on_aurora", + View::FtTotalEthSupplyOnNear => "ft_total_eth_supply_on_near", + View::FtMetadata => "ft_metadata", + View::StorageBalanceOf => "storage_balance_of", + View::PausedFlags => "get_paused_flags", + View::Erc20FromNep141 => "get_erc20_from_nep141", + View::Nep141FromErc20 => "get_nep141_from_erc20", + View::AccountsCounter => "get_accounts_counter", + } + } +} diff --git a/engine-workspace/src/result.rs b/engine-workspace/src/result.rs new file mode 100644 index 000000000..c341a5b0a --- /dev/null +++ b/engine-workspace/src/result.rs @@ -0,0 +1,166 @@ +use aurora_engine_types::borsh::BorshDeserialize; +use aurora_engine_types::types::Address; +use aurora_engine_types::{H256, U256}; +use near_sdk::{json_types::U128, PromiseOrValue}; +use serde::de::DeserializeOwned; +use workspaces::result::{ExecutionFinalResult, ExecutionOutcome, ViewResultDetails}; +use workspaces::types::Gas; + +#[derive(Debug, Eq, PartialOrd, PartialEq)] +pub struct ViewResult { + pub result: T, + pub logs: Vec, +} + +impl ViewResult { + pub fn json(view: ViewResultDetails) -> anyhow::Result { + Ok(Self { + result: view.json()?, + logs: view.logs, + }) + } +} + +impl ViewResult { + pub fn borsh(view: ViewResultDetails) -> anyhow::Result { + Ok(Self { + result: view.borsh()?, + logs: view.logs, + }) + } +} + +impl ViewResult> { + pub fn vec(view: ViewResultDetails) -> anyhow::Result { + Ok(Self { + result: view.result, + logs: view.logs, + }) + } +} + +impl ViewResult { + #[allow(non_snake_case)] + pub fn borsh_U256(view: ViewResultDetails) -> anyhow::Result { + let mut buf = [0u8; 32]; + buf.copy_from_slice(view.result.as_slice()); + Ok(Self { + result: U256::from(buf), + logs: view.logs, + }) + } +} + +impl ViewResult { + #[allow(non_snake_case)] + pub fn borsh_H256(view: ViewResultDetails) -> anyhow::Result { + let mut buf = [0u8; 32]; + buf.copy_from_slice(view.result.as_slice()); + Ok(Self { + result: H256::from(buf), + logs: view.logs, + }) + } +} + +#[derive(Debug)] +pub struct ExecutionResult { + inner: workspaces::result::ExecutionSuccess, + value: T, + success: bool, +} + +impl ExecutionResult { + pub fn json(result: ExecutionFinalResult) -> anyhow::Result { + let success = result.is_success(); + let inner = result.into_result()?; + let value = inner.json()?; + Ok(Self::new(inner, value, success)) + } +} + +impl TryFrom for ExecutionResult> { + type Error = anyhow::Error; + + fn try_from(result: ExecutionFinalResult) -> Result { + let success = result.is_success(); + let inner = result.into_result()?; + let res: U128 = inner.json()?; + let value = PromiseOrValue::Value(res); + Ok(Self::new(inner, value, success)) + } +} + +impl ExecutionResult { + pub fn borsh(result: ExecutionFinalResult) -> anyhow::Result { + let success = result.is_success(); + let inner = result.into_result()?; + let value = inner.borsh()?; + Ok(Self::new(inner, value, success)) + } +} + +impl ExecutionResult
{ + pub fn borsh_address(result: ExecutionFinalResult) -> anyhow::Result { + let success = result.is_success(); + let inner = result.into_result()?; + let bytes: Vec = inner.borsh()?; + let value = Address::try_from_slice(&bytes) + .map_err(|e| anyhow::anyhow!("Error while creating an address from slice: {e}"))?; + Ok(Self::new(inner, value, success)) + } +} + +impl ExecutionResult { + pub fn new(inner: workspaces::result::ExecutionSuccess, value: T, success: bool) -> Self { + Self { + inner, + value, + success, + } + } + + pub fn value(&self) -> &T { + &self.value + } + + pub fn into_value(self) -> T { + self.value + } + + pub fn total_gas_burnt(&self) -> Gas { + self.inner.total_gas_burnt + } + + pub fn outcome(&self) -> &ExecutionOutcome { + self.inner.outcome() + } + + pub fn outcomes(&self) -> Vec<&ExecutionOutcome> { + self.inner.outcomes() + } + + pub fn receipt_outcomes(&self) -> &[ExecutionOutcome] { + self.inner.receipt_outcomes() + } + + pub fn failures(&self) -> Vec<&ExecutionOutcome> { + self.inner.failures() + } + + pub fn receipt_failures(&self) -> Vec<&ExecutionOutcome> { + self.inner.receipt_failures() + } + + pub fn logs(&self) -> Vec<&str> { + self.inner.logs() + } + + pub fn is_success(&self) -> bool { + self.success + } + + pub fn is_failure(&self) -> bool { + !self.success + } +} diff --git a/engine-workspace/src/transaction.rs b/engine-workspace/src/transaction.rs new file mode 100644 index 000000000..0282fcd73 --- /dev/null +++ b/engine-workspace/src/transaction.rs @@ -0,0 +1,83 @@ +use aurora_engine_types::borsh::BorshSerialize; +use std::future::IntoFuture; +use workspaces::result::ExecutionFinalResult; +use workspaces::rpc::query::{Query, ViewFunction}; +use workspaces::rpc::BoxFuture; + +pub struct ViewTransaction<'a> { + pub(crate) inner: Query<'a, ViewFunction>, +} + +impl<'a> ViewTransaction<'a> { + pub(crate) fn new(view_tx: Query<'a, ViewFunction>) -> Self { + Self { inner: view_tx } + } + + pub fn args(mut self, args: Vec) -> Self { + self.inner = self.inner.args(args); + self + } + + pub fn args_json(mut self, args: U) -> Self { + self.inner = self.inner.args_json(args); + self + } + + pub fn args_borsh(mut self, args: U) -> Self { + self.inner = self.inner.args_borsh(args); + self + } +} + +impl<'a> IntoFuture for ViewTransaction<'a> { + type Output = anyhow::Result; + type IntoFuture = BoxFuture<'a, Self::Output>; + + fn into_future(self) -> Self::IntoFuture { + Box::pin(async { Ok(self.inner.await?) }.into_future()) + } +} + +pub struct CallTransaction<'a> { + inner: workspaces::operations::CallTransaction<'a>, +} + +impl<'a> CallTransaction<'a> { + pub(crate) fn new(call_tx: workspaces::operations::CallTransaction<'a>) -> Self { + Self { inner: call_tx } + } + + pub fn args(mut self, args: Vec) -> Self { + self.inner = self.inner.args(args); + self + } + + pub fn args_json(mut self, args: S) -> Self { + self.inner = self.inner.args_json(args); + self + } + + pub fn args_borsh(mut self, args: B) -> Self { + self.inner = self.inner.args_borsh(args); + self + } + + pub fn gas(mut self, gas: u64) -> Self { + self.inner = self.inner.gas(gas); + self + } + + pub fn max_gas(mut self) -> Self { + self.inner = self.inner.max_gas(); + self + } + + pub fn deposit(mut self, deposit: u128) -> Self { + self.inner = self.inner.deposit(deposit); + self + } + + pub async fn transact(self) -> anyhow::Result { + Ok(self.inner.transact().await?) + } +} diff --git a/engine/src/connector.rs b/engine/src/connector.rs index 9c1e01449..2616938b2 100644 --- a/engine/src/connector.rs +++ b/engine/src/connector.rs @@ -25,7 +25,7 @@ use aurora_engine_types::borsh; pub const ERR_NOT_ENOUGH_BALANCE_FOR_FEE: &str = "ERR_NOT_ENOUGH_BALANCE_FOR_FEE"; /// Indicate zero attached balance for promise call pub const ZERO_ATTACHED_BALANCE: Yocto = Yocto::new(0); -/// NEAR Gas for calling `fininsh_deposit` promise. Used in the `deposit` logic. +/// NEAR Gas for calling `finish_deposit` promise. Used in the `deposit` logic. pub const GAS_FOR_FINISH_DEPOSIT: NearGas = NearGas::new(50_000_000_000_000); /// NEAR Gas for calling `verify_log_entry` promise. Used in the `deposit` logic. // Note: Is 40Tgas always enough? diff --git a/engine/src/lib.rs b/engine/src/lib.rs index f1827852d..9fdf655d5 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -1042,8 +1042,7 @@ mod contract { #[no_mangle] pub extern "C" fn get_nep141_from_erc20() { let mut io = Runtime; - let erc20_address: crate::engine::ERC20Address = - io.read_input().to_vec().try_into().sdk_unwrap(); + let erc20_address: engine::ERC20Address = io.read_input().to_vec().try_into().sdk_unwrap(); io.return_output( engine::nep141_erc20_map(io) .lookup_right(&erc20_address) diff --git a/engine/src/state.rs b/engine/src/state.rs index 23316bbdf..9dabbec13 100644 --- a/engine/src/state.rs +++ b/engine/src/state.rs @@ -26,7 +26,7 @@ pub struct EngineState { } impl EngineState { - pub fn borsh_serialize(&self) -> Result, error::EngineStateError> { + pub fn borsh_serialize(&self) -> Result, EngineStateError> { let borshable: BorshableEngineState = self.into(); borshable .try_to_vec() @@ -34,10 +34,7 @@ impl EngineState { } /// Deserialization with lazy state migration. - pub fn try_from_slice( - bytes: &[u8], - io: &I, - ) -> Result { + pub fn try_from_slice(bytes: &[u8], io: &I) -> Result { let Ok(borshable) = BorshableEngineState::try_from_slice(bytes) else { let legacy = BorshableEngineStateV1::try_from_slice(bytes) .map_err(|_| EngineStateError::DeserializationFailed)?; diff --git a/engine/src/xcc.rs b/engine/src/xcc.rs index 245b9654b..552c53589 100644 --- a/engine/src/xcc.rs +++ b/engine/src/xcc.rs @@ -5,12 +5,14 @@ use aurora_engine_sdk::env::Env; use aurora_engine_sdk::io::{StorageIntermediate, IO}; use aurora_engine_sdk::promise::PromiseHandler; use aurora_engine_types::account_id::AccountId; -use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize}; +use aurora_engine_types::borsh::BorshSerialize; use aurora_engine_types::parameters::{PromiseAction, PromiseBatchAction, PromiseCreateArgs}; use aurora_engine_types::storage::{self, KeyPrefix}; use aurora_engine_types::types::{Address, NearGas, Yocto, ZERO_YOCTO}; use aurora_engine_types::{format, Cow, Vec, U256}; +pub use aurora_engine_types::parameters::xcc::{AddressVersionUpdateArgs, FundXccArgs}; + pub const ERR_NO_ROUTER_CODE: &str = "ERR_MISSING_XCC_BYTECODE"; pub const ERR_INVALID_ACCOUNT: &str = "ERR_INVALID_XCC_ACCOUNT"; pub const ERR_ATTACHED_NEAR: &str = "ERR_ATTACHED_XCC_NEAR"; @@ -25,9 +27,10 @@ pub const WITHDRAW_GAS: NearGas = NearGas::new(30_000_000_000_000); pub const WITHDRAW_TO_NEAR_SELECTOR: [u8; 4] = [0x6b, 0x35, 0x18, 0x48]; pub use aurora_engine_precompiles::xcc::state::{ - get_code_version_of_address, get_latest_code_version, get_wnear_address, CodeVersion, - ERR_CORRUPTED_STORAGE, STORAGE_AMOUNT, VERSION_KEY, WNEAR_KEY, + get_code_version_of_address, get_latest_code_version, get_wnear_address, ERR_CORRUPTED_STORAGE, + STORAGE_AMOUNT, VERSION_KEY, WNEAR_KEY, }; +pub use aurora_engine_types::parameters::xcc::CodeVersion; /// Type wrapper for router bytecode. #[derive(Debug, Clone, PartialEq, Eq)] @@ -45,18 +48,6 @@ impl<'a> RouterCode<'a> { } } -#[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize)] -pub struct AddressVersionUpdateArgs { - pub address: Address, - pub version: CodeVersion, -} - -#[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize)] -pub struct FundXccArgs { - pub target: Address, - pub wnear_account_id: Option, -} - pub fn fund_xcc_sub_account( io: &I, handler: &mut P, diff --git a/etc/tests/fibonacci/Cargo.toml b/etc/tests/fibonacci/Cargo.toml index e0c03bc1f..f8b8bcbc0 100644 --- a/etc/tests/fibonacci/Cargo.toml +++ b/etc/tests/fibonacci/Cargo.toml @@ -15,5 +15,5 @@ debug = false panic = "abort" [dependencies] -near-sdk = "4.0.0" +near-sdk = "4.1" serde = "1" diff --git a/etc/tests/ft-receiver/Cargo.toml b/etc/tests/ft-receiver/Cargo.toml index fd05e6f6a..ff30589ab 100644 --- a/etc/tests/ft-receiver/Cargo.toml +++ b/etc/tests/ft-receiver/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -near-sdk = "3.1.0" -near-contract-standards = "3.2.0" +near-sdk = "4.1" +near-contract-standards = "4.1" diff --git a/etc/xcc-router/Cargo.lock b/etc/xcc-router/Cargo.lock index c520814a7..e64886355 100644 --- a/etc/xcc-router/Cargo.lock +++ b/etc/xcc-router/Cargo.lock @@ -14,16 +14,42 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.10", "once_cell", "version_check", ] +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "version_check", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "arrayref" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" @@ -33,16 +59,16 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "8868f09ff8cea88b079da74ae569d9b8c62a23c68c746240b704ee6f7525c89c" [[package]] name = "aurora-engine-types" version = "1.0.0" dependencies = [ "base64 0.21.2", - "borsh 0.10.2", + "borsh 0.10.3", "borsh 0.9.3", "hex", "primitive-types 0.12.1", @@ -65,9 +91,9 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" @@ -104,25 +130,18 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", "generic-array", ] [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "borsh" version = "0.9.3" @@ -130,17 +149,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ "borsh-derive 0.9.3", - "hashbrown", + "hashbrown 0.11.2", ] [[package]] name = "borsh" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40f9ca3698b2e4cb7c15571db0abc5551dca417a21ae8140460b50309bb2cc62" +checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" dependencies = [ - "borsh-derive 0.10.2", - "hashbrown", + "borsh-derive 0.10.3", + "hashbrown 0.13.2", ] [[package]] @@ -153,20 +172,20 @@ dependencies = [ "borsh-schema-derive-internal 0.9.3", "proc-macro-crate 0.1.5", "proc-macro2", - "syn", + "syn 1.0.109", ] [[package]] name = "borsh-derive" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598b3eacc6db9c3ee57b22707ad8f6a8d2f6d442bfe24ffeb8cbb70ca59e6a35" +checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" dependencies = [ - "borsh-derive-internal 0.10.2", - "borsh-schema-derive-internal 0.10.2", + "borsh-derive-internal 0.10.3", + "borsh-schema-derive-internal 0.10.3", "proc-macro-crate 0.1.5", "proc-macro2", - "syn", + "syn 1.0.109", ] [[package]] @@ -177,18 +196,18 @@ checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "borsh-derive-internal" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186b734fa1c9f6743e90c95d7233c9faab6360d1a96d4ffa19d9cfd1e9350f8a" +checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -199,18 +218,18 @@ checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "borsh-schema-derive-internal" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b7ff1008316626f485991b960ade129253d4034014616b94f309a15366cc49" +checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -219,11 +238,17 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + [[package]] name = "byte-slice-cast" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "byteorder" @@ -233,15 +258,15 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bytesize" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" +checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5" [[package]] name = "c2-chacha" @@ -255,9 +280,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" @@ -273,15 +298,17 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" dependencies = [ - "libc", - "num-integer", + "android-tzdata", + "iana-time-zone", + "js-sys", "num-traits", "serde", "time", + "wasm-bindgen", "winapi", ] @@ -300,11 +327,17 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" dependencies = [ "libc", ] @@ -358,7 +391,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn", + "syn 1.0.109", ] [[package]] @@ -372,14 +405,20 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.3" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.4", "crypto-common", ] +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + [[package]] name = "easy-ext" version = "0.2.9" @@ -388,9 +427,9 @@ checksum = "53aff6fdc1b181225acdcb5b14c47106726fd8e486707315b1b138baed68ee31" [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "signature", ] @@ -438,9 +477,9 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -459,9 +498,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if 1.0.0", "libc", @@ -474,14 +513,29 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ - "ahash", + "ahash 0.7.6", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.3", ] [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hex" @@ -489,6 +543,29 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "impl-codec" version = "0.5.1" @@ -524,26 +601,69 @@ checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", ] [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "js-sys" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] [[package]] name = "keccak" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "libc" -version = "0.2.126" +version = "0.2.146" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" + +[[package]] +name = "log" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memory_units" @@ -551,11 +671,23 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +[[package]] +name = "near-abi" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73" +dependencies = [ + "borsh 0.9.3", + "schemars", + "semver", + "serde", +] + [[package]] name = "near-account-id" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de83d74a9241be8cc4eb3055216966b58bf8c463e8e285c0dc553925acdd19fa" +checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" dependencies = [ "borsh 0.9.3", "serde", @@ -563,9 +695,9 @@ dependencies = [ [[package]] name = "near-crypto" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ecf0b8b31aa7f4e60f629f72213a2617ca4a5f45cd1ae9ed2cf7cecfebdbb7" +checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" dependencies = [ "arrayref", "blake2", @@ -575,7 +707,6 @@ dependencies = [ "curve25519-dalek", "derive_more", "ed25519-dalek", - "libc", "near-account-id", "once_cell", "parity-secp256k1", @@ -590,9 +721,9 @@ dependencies = [ [[package]] name = "near-primitives" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ba19282e79a4485a77736b679d276b09870bbf8042a18e0f0ae36347489c5" +checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" dependencies = [ "borsh 0.9.3", "byteorder", @@ -619,9 +750,9 @@ dependencies = [ [[package]] name = "near-primitives-core" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb561feb392bb8c4f540256073446e6689af087bf6356e8dddcf75fc279f201f" +checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" dependencies = [ "base64 0.11.0", "borsh 0.9.3", @@ -630,47 +761,50 @@ dependencies = [ "near-account-id", "num-rational", "serde", - "sha2 0.10.2", + "sha2 0.10.6", "strum", ] [[package]] name = "near-rpc-error-core" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77fdd7ea8d8f786878651c37691515d5053f827ae60894aa40c16882b78f77c9" +checksum = "93ee0b41c75ef859c193a8ff1dadfa0c8207bc0ac447cc22259721ad769a1408" dependencies = [ "quote", "serde", - "syn", + "syn 1.0.109", ] [[package]] name = "near-rpc-error-macro" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e521842b6ae864dfe5391afbbe2df9e9d8427c26e9333b2e0b65cd42094f7607" +checksum = "8e837bd4bacd807073ec5ceb85708da7f721b46a4c2a978de86027fb0034ce31" dependencies = [ "near-rpc-error-core", "serde", - "syn", + "syn 1.0.109", ] [[package]] name = "near-sdk" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda34e06e28fb9a09ac54efbdc49f0c9308780fc932aaa81c49c493fde974045" +checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "borsh 0.9.3", "bs58", + "near-abi", "near-crypto", "near-primitives", "near-primitives-core", "near-sdk-macros", "near-sys", "near-vm-logic", + "once_cell", + "schemars", "serde", "serde_json", "wee_alloc", @@ -678,14 +812,14 @@ dependencies = [ [[package]] name = "near-sdk-macros" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72064fcc15a623a0d40a6c199ea5cbdc30a83cae4816889d46f218acf31bfba8" +checksum = "4907affc9f5ed559456509188ff0024f1f2099c0830e6bdb66eb61d5b75912c0" dependencies = [ "Inflector", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -696,9 +830,9 @@ checksum = "e307313276eaeced2ca95740b5639e1f3125b7c97f0a1151809d105f1aa8c6d3" [[package]] name = "near-vm-errors" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e02faf2bc1f6ef82b965cfe44389808fb5594f7aca4b596766117f4ce74df20" +checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" dependencies = [ "borsh 0.9.3", "near-account-id", @@ -708,11 +842,11 @@ dependencies = [ [[package]] name = "near-vm-logic" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f024d90451cd3c24d7a0a5cabf3636b192a60eb8e3ff0456f6c18b91152c346d" +checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "borsh 0.9.3", "bs58", "byteorder", @@ -723,8 +857,9 @@ dependencies = [ "near-vm-errors", "ripemd", "serde", - "sha2 0.10.2", + "sha2 0.10.6", "sha3", + "zeropool-bn", ] [[package]] @@ -772,9 +907,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -788,7 +923,7 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909" dependencies = [ - "arrayvec 0.7.2", + "arrayvec 0.7.3", "bitvec", "byte-slice-cast", "impl-trait-for-tuples", @@ -802,10 +937,10 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" dependencies = [ - "proc-macro-crate 1.2.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -822,9 +957,9 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "primitive-types" @@ -860,29 +995,28 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d50bfb8c23f23915855a00d98b5a35ef2e0b871bb52937bacadb798fbb66c8" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "thiserror", - "toml", + "toml_edit", ] [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -914,7 +1048,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha 0.3.1", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -934,7 +1068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -948,11 +1082,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.10", ] [[package]] @@ -975,18 +1109,18 @@ dependencies = [ [[package]] name = "ripemd" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1facec54cb5e0dc08553501fa740091086d0259ad0067e0d4103448e4cb22ed3" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ - "digest 0.10.3", + "digest 0.10.7", ] [[package]] name = "rlp" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "999508abb0ae792aabed2460c45b89106d97fe4adac593bdaef433c2605847b5" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ "bytes", "rustc-hex", @@ -1009,47 +1143,82 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.8" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c8ad4f0c00e1eb5bc7614d236a7f1300e3dbd76b68cac8e06fb00b015ad8d8" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "schemars" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] [[package]] name = "semver" -version = "1.0.12" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.118" +version = "1.0.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" +checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.118" +version = "1.0.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", @@ -1071,38 +1240,36 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.3", + "digest 0.10.7", ] [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", + "digest 0.10.7", "keccak", - "opaque-debug", ] [[package]] name = "signature" -version = "1.5.0" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smart-default" @@ -1112,9 +1279,15 @@ checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "static_assertions" version = "1.1.0" @@ -1132,44 +1305,43 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4faebde00e8ff94316c01800f9054fd2ba77d30d9e922541913051d1d978918b" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ "heck", "proc-macro2", "quote", "rustversion", - "syn", + "syn 1.0.109", ] [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "1.0.57" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] -name = "synstructure" -version = "0.12.6" +name = "syn" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ "proc-macro2", "quote", - "syn", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1180,29 +1352,29 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.18", ] [[package]] name = "time" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", @@ -1211,24 +1383,41 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" + +[[package]] +name = "toml_edit" +version = "0.19.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "typenum" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "uint" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ "byteorder", "crunchy", @@ -1238,15 +1427,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" - -[[package]] -name = "unicode-xid" -version = "0.2.3" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" [[package]] name = "version_check" @@ -1272,6 +1455,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.18", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + [[package]] name = "wee_alloc" version = "0.4.5" @@ -1306,6 +1543,81 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winnow" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699" +dependencies = [ + "memchr", +] + [[package]] name = "wyz" version = "0.2.0" @@ -1331,12 +1643,25 @@ dependencies = [ [[package]] name = "zeroize_derive" -version = "1.3.2" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn", - "synstructure", + "syn 2.0.18", +] + +[[package]] +name = "zeropool-bn" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e61de68ede9ffdd69c01664f65a178c5188b73f78faa21f0936016a888ff7c" +dependencies = [ + "borsh 0.9.3", + "byteorder", + "crunchy", + "lazy_static", + "rand 0.8.5", + "rustc-hex", ] diff --git a/etc/xcc-router/Cargo.toml b/etc/xcc-router/Cargo.toml index ce5db7e32..c9fe89312 100644 --- a/etc/xcc-router/Cargo.toml +++ b/etc/xcc-router/Cargo.toml @@ -16,7 +16,7 @@ panic = "abort" [dependencies] aurora-engine-types = { path = "../../engine-types", default-features = false, features = ["borsh-compat"] } -near-sdk = "4.0.0" +near-sdk = "4.1" [features] default = []