From 7b8102a4e72c69c80da81db37a2785ef66783aef Mon Sep 17 00:00:00 2001 From: canonbrother Date: Mon, 10 Apr 2023 11:09:50 +0800 Subject: [PATCH] chore(workflow): evm ci (#1866) * add ci for evm * toolchain nightly will do * add cargo clippy ci * Add EVM BlockHandler (#1864) * Make handlers extensible, add block handler * Move EVMHandler * Fix build errors * Add connect_block * Fix Eth_GetBlockByHash * Fix incomplete merge * Add bin files to gitignore * Change RPC methods to lowerCamelCase * Formatting * EVM in/out refinements (#1865) * Return error on sub balance failure. * Change to expected return type * Update EVM in/out TX * Use array instead of rust::Vec * Pass context to CustomTxVisit * Add temporary state to TransactionQueue * Improve readability * Block integration test --------- Co-authored-by: Bushstar Co-authored-by: Prasanna Loganathar * Revert "EVM in/out refinements (#1865)" (#1867) This reverts commit 35c85d4938d6cd1170ed7f90ce82b4dbeaf5c49b. * EVM in/out refinements (#1868) * Return error on sub balance failure. * Change to expected return type * Update EVM in/out TX * Use array instead of rust::Vec * Pass context to CustomTxVisit * Add temporary state to TransactionQueue * Improve readability * Block integration test --------- Co-authored-by: Bushstar * Fix warnings (#1869) * Got correct hash for public key recovery. Add test. (#1870) * Got correct hash for public key recovery. Add test. * Add support for EIP1559 TXs address recovery * Add support for EIP2930 TXs address recovery * Add failing test * Improve error handling (#1872) * Improve error handling * Correct test addresses * Fix public key extraction from Eth TXs and add tests (#1875) * Get correct hash for public key recovery. Add test. * Update test for EIP-2930 * EVM block integration test (#1874) * Add smart contract create && call tests * evm ci event triggered by path * fmt --------- Co-authored-by: Shoham Chakraborty Co-authored-by: Jouzo <15011228+Jouzo@users.noreply.github.com> Co-authored-by: Bushstar Co-authored-by: Prasanna Loganathar --- .github/workflows/tests-evm.yml | 74 +++++++++++++++++++ src/rust/crates/ain-evm-state/src/tx_queue.rs | 6 +- src/rust/crates/ain-evm/src/transaction.rs | 9 ++- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/tests-evm.yml diff --git a/.github/workflows/tests-evm.yml b/.github/workflows/tests-evm.yml new file mode 100644 index 0000000000..6af960983e --- /dev/null +++ b/.github/workflows/tests-evm.yml @@ -0,0 +1,74 @@ +name: Tests - EVM + +on: + push: + paths: [ src/rust/** ] + + pull_request: + paths: [ src/rust/** ] + +jobs: + lint_cargo_fmt: + name: Lint (cargo fmt) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af + with: + profile: minimal + toolchain: nightly + target: wasm32-unknown-unknown + default: true + override: true + components: rustfmt, clippy + + - run: | + cd src/rust + cargo fmt --all -- --check + + lint_cargo_clippy: + name: Lint (cargo clippy) + runs-on: ubuntu-latest + steps: + - uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af + with: + profile: minimal + toolchain: nightly + target: wasm32-unknown-unknown + default: true + override: true + components: rustfmt, clippy + + - run: | + cd src/rust + cargo clippy + + test_cargo: + name: Test (cargo) + runs-on: ubuntu-latest + steps: + - uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af + with: + profile: minimal + toolchain: nightly + target: wasm32-unknown-unknown + default: true + override: true + components: rustfmt, clippy + + - run: | + cd src/rust + cargo test --no-fail-fast diff --git a/src/rust/crates/ain-evm-state/src/tx_queue.rs b/src/rust/crates/ain-evm-state/src/tx_queue.rs index e0c8178b06..cc301a4540 100644 --- a/src/rust/crates/ain-evm-state/src/tx_queue.rs +++ b/src/rust/crates/ain-evm-state/src/tx_queue.rs @@ -84,7 +84,11 @@ impl TransactionQueueMap { } pub fn state(&self, context_id: u64) -> Option { - self.queues.read().unwrap().get(&context_id).map(|queue| queue.state()) + self.queues + .read() + .unwrap() + .get(&context_id) + .map(|queue| queue.state()) } } diff --git a/src/rust/crates/ain-evm/src/transaction.rs b/src/rust/crates/ain-evm/src/transaction.rs index 67bd43fe13..af6593020b 100644 --- a/src/rust/crates/ain-evm/src/transaction.rs +++ b/src/rust/crates/ain-evm/src/transaction.rs @@ -123,7 +123,7 @@ impl TryFrom for SignedTx { tx.signature.s(), tx.signature.standard_v(), ) - }, + } TransactionV2::EIP2930(tx) => { let msg = ethereum::EIP2930TransactionMessage { chain_id: tx.chain_id, @@ -138,7 +138,7 @@ impl TryFrom for SignedTx { let signing_message = libsecp256k1::Message::parse_slice(&msg.hash()[..]).unwrap(); let hash = H256::from(signing_message.serialize()); recover_public_key(&hash, &tx.r, &tx.s, tx.odd_y_parity as u8) - }, + } TransactionV2::EIP1559(tx) => { let msg = ethereum::EIP1559TransactionMessage { chain_id: tx.chain_id, @@ -317,6 +317,9 @@ mod tests { // EIP-2930 let signed_tx = crate::transaction::SignedTx::try_from("01f86d050185689451eee18252089434c1ca09a2dc717d89baef2f30ff6a6b2975e17e872386f26fc1000080c080a0632502442f6bd0dbe14c087798277ce04bdede53c4642559a0a7d7e20fc7e8f1a0517c7504cb9adfe67f58dd43e00e77b4b2159e9f2c378b7616ba30dfa711ec8f").unwrap(); - assert_eq!(hex::encode(signed_tx.sender.as_fixed_bytes()), "f829754bae400b679febefdcfc9944c323e1f94e"); + assert_eq!( + hex::encode(signed_tx.sender.as_fixed_bytes()), + "f829754bae400b679febefdcfc9944c323e1f94e" + ); } }