Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix: serialize vesting (#324)
Browse files Browse the repository at this point in the history
* fix serialization for vesting; rearrange structure;

* remove folder from scripts

* install opencl deps
  • Loading branch information
rllola authored Feb 28, 2023
1 parent 2e0775e commit 807d352
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 683 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -114,14 +115,17 @@ 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

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

Expand Down
4 changes: 4 additions & 0 deletions contracts/v0.8/cbor/MinerCbor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ library MinerCBOR {

uint byteIdx = 0;
uint len;
uint leni;

(len, byteIdx) = rawResp.readFixedArray(byteIdx);
assert(len == 1);
Expand All @@ -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);

Expand Down
37 changes: 37 additions & 0 deletions contracts/v0.8/tests/deserializeparams.test.sol
Original file line number Diff line number Diff line change
@@ -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");
}
}
Loading

0 comments on commit 807d352

Please sign in to comment.