From 807d35263c666d54768825471d6948422f893552 Mon Sep 17 00:00:00 2001 From: sleepy ramen Date: Tue, 28 Feb 2023 16:59:09 +0100 Subject: [PATCH] fix: serialize vesting (#324) * fix serialization for vesting; rearrange structure; * remove folder from scripts * install opencl deps --- .github/workflows/main.yaml | 60 ++ Makefile | 6 +- contracts/v0.8/cbor/MinerCbor.sol | 4 + .../v0.8/tests/deserializeparams.test.sol | 37 + scripts/frc42/Cargo.lock | 660 ------------------ scripts/frc42/Cargo.toml | 9 - scripts/{leb128 => }/generate.py | 0 scripts/{leb128 => }/u_case.txt | 0 .../main.rs => testing/examples/methodnum.rs | 33 +- testing/examples/serializeParams.rs | 14 + testing/tests/deserializeParams.rs | 77 ++ 11 files changed, 217 insertions(+), 683 deletions(-) create mode 100644 contracts/v0.8/tests/deserializeparams.test.sol delete mode 100644 scripts/frc42/Cargo.lock delete mode 100644 scripts/frc42/Cargo.toml rename scripts/{leb128 => }/generate.py (100%) rename scripts/{leb128 => }/u_case.txt (100%) rename scripts/frc42/src/main.rs => testing/examples/methodnum.rs (95%) create mode 100644 testing/examples/serializeParams.rs create mode 100644 testing/tests/deserializeParams.rs diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 19938ac1..e094e1fa 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -652,6 +652,8 @@ jobs: uses: actions/checkout@v2 with: submodules: 'false' + - name: Instal deps + run: make install-opencl - name: Install latest stable uses: actions-rs/toolchain@v1 with: @@ -831,6 +833,64 @@ jobs: rustup target add wasm32-unknown-unknown cargo test address + deserialize-test: + name: "Deserialize Params Tests" + timeout-minutes: 20 + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: 'true' + - name: Instal deps + run: make install-opencl + - name: Install node + uses: actions/setup-node@v2 + with: + node-version: '16.16.0' + - name: Install yarn + run: npm install -g yarn + - name: Install latest stable + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - name: Install dependencies + run: | + yarn install + make install_solc_linux + - name: Restore crates + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: ${{ runner.os }}-cargo-${{ hashFiles('./testing/Cargo.lock') }} + - name: Restore previous compilation + uses: actions/cache@v3 + with: + path: | + ./testing/target + key: ${{ runner.os }}-testing-${{ hashFiles('./testing/Cargo.lock') }} + - name: Restore builtin-actors + uses: actions/cache@v3 + with: + path: | + ./testing/builtin-actors/target + key: ${{ runner.os }}-actors-${{ hashFiles('./testing/builtin-actors/Cargo.lock') }} + - name: Build builtin-actors + run: make build_builtin_actors + - name: Build contracts + run: make + - name: Run tests for deserialize params + run: | + cd testing + rustup target add wasm32-unknown-unknown + cargo test deserialize_params_tests + + comment-result: name: "Comment the result on PR" runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index 60e16866..7d7aced4 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ build_tests: verify_solc build_leb128_test ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/send.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/cbor.decode.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/address.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi + ./bin/solc solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/tests/deserializeparams.test.sol --output-dir ./build/v0.8/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc @zondax/solidity-bignumber=${PWD}/node_modules/@zondax/solidity-bignumber/ solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/mocks/tests/market.test.sol --output-dir ./build/v0.8/mocks/tests --overwrite --bin --hashes --opcodes --abi ./bin/solc @zondax/solidity-bignumber=${PWD}/node_modules/@zondax/solidity-bignumber/ solidity-cborutils=${PWD}/node_modules/solidity-cborutils/ @ensdomains=${PWD}/node_modules/@ensdomains/ contracts/v0.8/mocks/tests/miner.test.sol --output-dir ./build/v0.8/mocks/tests --overwrite --bin --hashes --opcodes --abi @@ -114,7 +115,7 @@ test_send_integration: build build_builtin_actors cd testing && cargo test send_test -- --nocapture test_frc0042: - cd scripts/frc42 && cargo r + cd testing && cargo run --example methodnum test_cbor_decode: build build_builtin_actors cd testing && cargo test cbor_decode_test -- --nocapture @@ -122,6 +123,9 @@ test_cbor_decode: build build_builtin_actors test_leb128: build build_builtin_actors cd testing && cargo test leb128 -- --nocapture +test_deserialize: build build_builtin_actors + cd testing && cargo test deserialize_params_tests -- --nocapture + test_address: build build_builtin_actors cd testing && cargo test address -- --nocapture diff --git a/contracts/v0.8/cbor/MinerCbor.sol b/contracts/v0.8/cbor/MinerCbor.sol index 193e9f08..9354e317 100644 --- a/contracts/v0.8/cbor/MinerCbor.sol +++ b/contracts/v0.8/cbor/MinerCbor.sol @@ -136,6 +136,7 @@ library MinerCBOR { uint byteIdx = 0; uint len; + uint leni; (len, byteIdx) = rawResp.readFixedArray(byteIdx); assert(len == 1); @@ -144,6 +145,9 @@ library MinerCBOR { ret.vesting_funds = new MinerTypes.VestingFunds[](len); for (uint i = 0; i < len; i++) { + (leni, byteIdx) = rawResp.readFixedArray(byteIdx); + assert(leni == 2); + (epoch, byteIdx) = rawResp.readInt64(byteIdx); (tmp, byteIdx) = rawResp.readBytes(byteIdx); diff --git a/contracts/v0.8/tests/deserializeparams.test.sol b/contracts/v0.8/tests/deserializeparams.test.sol new file mode 100644 index 00000000..6e13d01e --- /dev/null +++ b/contracts/v0.8/tests/deserializeparams.test.sol @@ -0,0 +1,37 @@ +/******************************************************************************* + * (c) 2023 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ +// +// DRAFT!! THIS CODE HAS NOT BEEN AUDITED - USE ONLY FOR PROTOTYPING + +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.17; + +import "../types/MinerTypes.sol"; +import "../cbor/MinerCbor.sol"; + +/// @notice This file is meant to serve as a deployable contract to test +/// @author Zondax AG +contract DeserializeParamsTest { + using MinerCBOR for *; + + function deserializeGetVestingFundsReturn() public pure { + bytes memory params = hex"8181820040"; + + MinerTypes.GetVestingFundsReturn memory result = params.deserializeGetVestingFundsReturn(); + + require(result.vesting_funds.length == 1, "result length should be 1"); + } +} \ No newline at end of file diff --git a/scripts/frc42/Cargo.lock b/scripts/frc42/Cargo.lock deleted file mode 100644 index 840806e9..00000000 --- a/scripts/frc42/Cargo.lock +++ /dev/null @@ -1,660 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" - -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "blake2b_simd" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "cbor4ii" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebce4be718fce03915a0a6220eaca81becdab6485d6ad57d483ed6ff76def7b7" -dependencies = [ - "serde", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "cid" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ed9c8b2d17acb8110c46f1da5bf4a696d745e1474a16db0cd2b49cd0249bf2" -dependencies = [ - "core2", - "multibase", - "multihash", - "serde", - "serde_bytes", - "unsigned-varint", -] - -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - -[[package]] -name = "core2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" -dependencies = [ - "memchr", -] - -[[package]] -name = "cpufeatures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "data-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" - -[[package]] -name = "data-encoding-macro" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" -dependencies = [ - "data-encoding", - "data-encoding-macro-internal", -] - -[[package]] -name = "data-encoding-macro-internal" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" -dependencies = [ - "data-encoding", - "syn", -] - -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "frc42_dispatch" -version = "1.0.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#8fd6f9ca24f2c190573dae2ef49b4cbe6fcf33b5" -dependencies = [ - "frc42_hasher", - "frc42_macros", - "fvm_ipld_encoding", - "fvm_sdk", - "fvm_shared", - "thiserror", -] - -[[package]] -name = "frc42_hasher" -version = "1.0.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#8fd6f9ca24f2c190573dae2ef49b4cbe6fcf33b5" -dependencies = [ - "fvm_sdk", - "fvm_shared", - "thiserror", -] - -[[package]] -name = "frc42_macros" -version = "1.0.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#8fd6f9ca24f2c190573dae2ef49b4cbe6fcf33b5" -dependencies = [ - "blake2b_simd", - "frc42_hasher", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "fvm_ipld_blockstore" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688239a96199577f6705a3f9689abfd795f867f91f5847bc7e236017cc672df7" -dependencies = [ - "anyhow", - "cid", - "multihash", -] - -[[package]] -name = "fvm_ipld_encoding" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf531c59e7c9a4c9044a34d1b44c9d544fab1eb0ba50aaa18121fe698d4fec35" -dependencies = [ - "anyhow", - "cid", - "fvm_ipld_blockstore", - "multihash", - "serde", - "serde_ipld_dagcbor", - "serde_repr", - "serde_tuple", - "thiserror", -] - -[[package]] -name = "fvm_sdk" -version = "3.0.0-alpha.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "820720405923ef64f9ec5b1c7bb523629763d888f34904c8ff3bdd69de652195" -dependencies = [ - "cid", - "fvm_ipld_encoding", - "fvm_shared", - "lazy_static", - "log", - "num-traits", - "thiserror", -] - -[[package]] -name = "fvm_shared" -version = "3.0.0-alpha.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c716adb0c618a2ce9c3e464cdbe1f00c65cc0a18e83d4aae7be38e52895e0a5" -dependencies = [ - "anyhow", - "bitflags", - "blake2b_simd", - "byteorder", - "cid", - "data-encoding", - "data-encoding-macro", - "fvm_ipld_blockstore", - "fvm_ipld_encoding", - "lazy_static", - "log", - "multihash", - "num-bigint", - "num-derive", - "num-integer", - "num-traits", - "serde", - "serde_repr", - "serde_tuple", - "thiserror", - "unsigned-varint", -] - -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "keccak" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" -dependencies = [ - "cpufeatures", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "multibase" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" -dependencies = [ - "base-x", - "data-encoding", - "data-encoding-macro", -] - -[[package]] -name = "multihash" -version = "0.16.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" -dependencies = [ - "blake2b_simd", - "core2", - "digest", - "multihash-derive", - "ripemd", - "serde", - "serde-big-array", - "sha2", - "sha3", - "unsigned-varint", -] - -[[package]] -name = "multihash-derive" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" -dependencies = [ - "proc-macro-crate", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "proc-macro-crate" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" -dependencies = [ - "thiserror", - "toml", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "script" -version = "0.1.0" -dependencies = [ - "frc42_dispatch", -] - -[[package]] -name = "serde" -version = "1.0.148" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde-big-array" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd31f59f6fe2b0c055371bb2f16d7f0aa7d8881676c04a55b1596d1a17cd10a4" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_bytes" -version = "0.11.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.148" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_ipld_dagcbor" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e23de7a4a18dff77ab9531f279a882500b8cf3549fde044d4e10481b411f1e" -dependencies = [ - "cbor4ii", - "cid", - "scopeguard", - "serde", -] - -[[package]] -name = "serde_repr" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_tuple" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f025b91216f15a2a32aa39669329a475733590a015835d1783549a56d09427" -dependencies = [ - "serde", - "serde_tuple_macros", -] - -[[package]] -name = "serde_tuple_macros" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4076151d1a2b688e25aaf236997933c66e18b870d0369f8b248b8ab2be630d7e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha3" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" -dependencies = [ - "digest", - "keccak", -] - -[[package]] -name = "syn" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce" -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", - "unicode-xid", -] - -[[package]] -name = "thiserror" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - -[[package]] -name = "unicode-ident" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "unsigned-varint" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" diff --git a/scripts/frc42/Cargo.toml b/scripts/frc42/Cargo.toml deleted file mode 100644 index fa7c4140..00000000 --- a/scripts/frc42/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "script" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -frc42_dispatch = { git = "https://github.com/filecoin-project/filecoin-actor-utils", branch = "feat/fvm-m2" } diff --git a/scripts/leb128/generate.py b/scripts/generate.py similarity index 100% rename from scripts/leb128/generate.py rename to scripts/generate.py diff --git a/scripts/leb128/u_case.txt b/scripts/u_case.txt similarity index 100% rename from scripts/leb128/u_case.txt rename to scripts/u_case.txt diff --git a/scripts/frc42/src/main.rs b/testing/examples/methodnum.rs similarity index 95% rename from scripts/frc42/src/main.rs rename to testing/examples/methodnum.rs index dc0dd97d..c7e7f61b 100644 --- a/scripts/frc42/src/main.rs +++ b/testing/examples/methodnum.rs @@ -1,5 +1,12 @@ use std::fs; + /***************************************** + * + * This file is used only to generate and + * compare the method num using FRC42 + * + *****************************************/ + fn main() { /********************************* @@ -55,7 +62,7 @@ fn main() { println!("GetDealActivationExported {}", GetDealActivationExported); // Verify we have the right one - let file = fs::read_to_string("../../contracts/v0.8/types/MarketTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/MarketTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -148,7 +155,7 @@ fn main() { println!("GetMultiaddrsExported {}", GetMultiaddrsExported); // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/MinerTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/MinerTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -195,7 +202,7 @@ fn main() { println!("MinerConsensusCountExported {}", MinerConsensusCountExported); // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/PowerTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/PowerTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -242,7 +249,7 @@ fn main() { println!("RemoveExpiredClaimsExported {}", RemoveExpiredClaimsExported); // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/VerifRegTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/VerifRegTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -317,7 +324,7 @@ fn main() { println!("AllowanceExported {}", AllowanceExported); // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/DataCapTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/DataCapTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -348,7 +355,7 @@ fn main() { println!("ExecExported {}", ExecExported); // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/InitTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/InitTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -379,7 +386,7 @@ fn main() { println!("AuthenticateMessageExported {}", AuthenticateMessageExported); // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/AccountTypes.sol").unwrap(); + let file = fs::read_to_string("../contracts/v0.8/types/AccountTypes.sol").unwrap(); 'method: for (method, method_num ) in method_nums { for line in file.lines() { @@ -401,16 +408,16 @@ fn main() { println!("COMMON EXPORTED METHOD NUM"); let mut method_nums: Vec<(String, u64)> = vec![]; - + let UniversalReceiverHook = frc42_dispatch::method_hash!("Receive"); method_nums.push(("UniversalReceiverHookMethodNum".to_string(), UniversalReceiverHook)); - - + + println!("UniversalReceiverHookMethodNum {}", UniversalReceiverHook); - + // Verify we have the right ones - let file = fs::read_to_string("../../contracts/v0.8/types/CommonTypes.sol").unwrap(); - + let file = fs::read_to_string("../contracts/v0.8/types/CommonTypes.sol").unwrap(); + 'method: for (method, method_num ) in method_nums { for line in file.lines() { if line.contains(&format!(" {} ",method)) { diff --git a/testing/examples/serializeParams.rs b/testing/examples/serializeParams.rs new file mode 100644 index 00000000..6d619697 --- /dev/null +++ b/testing/examples/serializeParams.rs @@ -0,0 +1,14 @@ +use fil_actor_miner::GetVestingFundsReturn; +use fvm_shared::clock::ChainEpoch; +use fvm_shared::econ::TokenAmount; +use fvm_ipld_encoding::to_vec; + +fn main() { + + let vf = GetVestingFundsReturn { + vesting_funds: vec![(ChainEpoch::default(), TokenAmount::default())] + }; + + println!("{}", hex::encode(to_vec(&vf).unwrap())) + +} \ No newline at end of file diff --git a/testing/tests/deserializeParams.rs b/testing/tests/deserializeParams.rs new file mode 100644 index 00000000..f0b1c1e6 --- /dev/null +++ b/testing/tests/deserializeParams.rs @@ -0,0 +1,77 @@ +use fil_actor_eam::Return; +use fil_actor_evm::Method as EvmMethods; +use fil_actors_runtime::EAM_ACTOR_ADDR; +use fvm::executor::{ApplyKind, Executor}; +use fvm_integration_tests::dummy::DummyExterns; +use fvm_integration_tests::tester::Account; +use fvm_ipld_encoding::strict_bytes; +use fvm_ipld_encoding::RawBytes; +use fvm_shared::address::Address; +use fvm_shared::message::Message; +use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize}; + +use testing::setup; + +const WASM_COMPILED_PATH: &str = "../build/v0.8/tests/DeserializeParamsTest.bin"; + +#[derive(SerdeSerialize, SerdeDeserialize)] +#[serde(transparent)] +pub struct CreateExternalParams(#[serde(with = "strict_bytes")] pub Vec); + +#[test] +fn deserialize_params_tests() { + println!("Testing solidity API"); + + let (mut tester, _manifest) = setup::setup_tester(); + + let sender: [Account; 1] = tester.create_accounts().unwrap(); + + // Instantiate machine + tester.instantiate_machine(DummyExterns).unwrap(); + + let executor = tester.executor.as_mut().unwrap(); + + println!("Calling init actor (EVM)"); + + let evm_bin = setup::load_evm(WASM_COMPILED_PATH); + + let constructor_params = CreateExternalParams(evm_bin); + + let message = Message { + from: sender[0].1, + to: EAM_ACTOR_ADDR, + gas_limit: 1000000000, + method_num: 4, + sequence: 0, + params: RawBytes::serialize(constructor_params).unwrap(), + ..Message::default() + }; + + let res = executor + .execute_message(message, ApplyKind::Explicit, 100) + .unwrap(); + + assert_eq!(res.msg_receipt.exit_code.value(), 0); + + let exec_return: Return = RawBytes::deserialize(&res.msg_receipt.return_data).unwrap(); + + let contract_actor_id = exec_return.actor_id; + + println!("Calling `deserializeGetVestingFundsReturn`"); + + let message = Message { + from: sender[0].1, + to: Address::new_id(contract_actor_id), + gas_limit: 1000000000, + method_num: EvmMethods::InvokeContract as u64, + sequence: 1, + params: RawBytes::new(hex::decode("4407854007").unwrap()), + ..Message::default() + }; + + let res = executor + .execute_message(message, ApplyKind::Explicit, 100) + .unwrap(); + + assert_eq!(res.msg_receipt.exit_code.value(), 0); +} \ No newline at end of file