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

Commit

Permalink
Merge commit 'a3afb7926133c90ceaf7df873dcf789bc8dfed95' into xavier-s…
Browse files Browse the repository at this point in the history
…taking
  • Loading branch information
aurexav committed Dec 5, 2021
2 parents 7b1cedc + a3afb79 commit c884a9e
Show file tree
Hide file tree
Showing 56 changed files with 2,268 additions and 111 deletions.
41 changes: 25 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ on:
- "**.lock"
- "**.json"
- "**.yml"
# issue_comment:
# types: [created, edited]

env:
RUST_TOOLCHAIN: nightly
Expand All @@ -49,9 +47,13 @@ jobs:
target: subalfred
include:
- action: build
features: --features template
flags: --release --features template
task:
target: drml
- action: build
flags: --release
task:
target: subalfred

steps:
- name: Install Rust ${{ env.RUST_TOOLCHAIN }} toolchain
Expand All @@ -77,12 +79,12 @@ jobs:
${{ matrix.action }}-${{ matrix.task.target }}-${{ env.GITHUB_CACHE_VERSION }}-
- name: Action ${{ matrix.action }}
run: cargo ${{ matrix.action }} ${{ matrix.features }} --locked
run: cargo ${{ matrix.action }} ${{ matrix.flags }} --locked

- name: Compress ${{ matrix.task.target }}
if: matrix.action != 'test'
run: |
mv target/debug/${{ matrix.task.target }} .
mv target/release/${{ matrix.task.target }} .
tar cf ${{ matrix.task.target }}.tar.zst ${{ matrix.task.target }} -I pzstd
- name: Upload ${{ matrix.task.target }}
Expand All @@ -96,11 +98,21 @@ jobs:
if: matrix.task.target == 'drml' && matrix.action == 'build'
run: .maintain/purge-large-cache.sh

rpc-checks:
name: Task test RPC
dvm-checks:
name: Task test ${{ matrix.task.target }} DVM testcases
if: github.event_name == 'push' || !github.event.pull_request.draft
needs: [basic-checks]
runs-on: ubuntu-latest
strategy:
matrix:
task:
- target: darwinia
run: npm test
- target: frontier
run: |
npm run build
npm run test
steps:
- name: Download drml
uses: actions/download-artifact@v2
Expand All @@ -113,9 +125,8 @@ jobs:
sudo mv drml /usr/bin
- name: Launch drml
run: |
drml --unsafe-ws-external --unsafe-rpc-external --rpc-cors all --rpc-methods unsafe --chain pangolin-dev --alice &
sleep 120
if: matrix.task.target == 'darwinia'
run: drml --unsafe-ws-external --unsafe-rpc-external --rpc-cors all --rpc-methods unsafe --chain pangolin-dev --alice &

- name: Install nodejs ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
Expand All @@ -125,16 +136,15 @@ jobs:
- name: Fetch latest code
uses: actions/checkout@v2

- name: Test
- name: Action test
run: |
cd tests/dvm
cd tests/dvm/${{ matrix.task.target }}
npm install
npm test
${{ matrix.task.run }}
code-checks:
name: Task check code
if: github.event_name == 'push' || !github.event.pull_request.draft
# if: github.event.issue.pull_request && contains(github.event.comment.body, '/bot check') && contains(github.event.comment.body, 'code')
needs: [basic-checks]
runs-on: ubuntu-latest
steps:
Expand All @@ -157,7 +167,6 @@ jobs:
runtime-checks:
name: Task check runtime
if: github.event_name == 'push' || !github.event.pull_request.draft
# if: github.event.issue.pull_request && contains(github.event.comment.body, '/bot check') && contains(github.event.comment.body, 'runtime')
needs: [basic-checks]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -246,7 +255,7 @@ jobs:
housekeeping-checks:
name: Task check housekeeping
if: always()
needs: [rpc-checks, code-checks, runtime-checks]
needs: [dvm-checks, code-checks, runtime-checks]
steps:
- name: Clean artifacts
uses: geekyeggo/delete-artifact@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target
## Npm
package-lock.json
node_modules
build

# Test Data
## Pangolin Local Testnet
Expand Down
5 changes: 3 additions & 2 deletions client/dvm/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ where
pending_transactions: PendingTransactions,
backend: Arc<dc_db::Backend<B>>,
is_authority: bool,
signers: Vec<Box<dyn EthSigner>>,
max_past_logs: u32,
) -> Self {
Self {
Expand All @@ -105,7 +106,7 @@ where
pending_transactions,
backend,
is_authority,
signers: Vec::new(),
signers,
max_past_logs,
_marker: PhantomData,
}
Expand Down Expand Up @@ -784,7 +785,7 @@ where

for signer in &self.signers {
if signer.accounts().contains(&from) {
match signer.sign(message) {
match signer.sign(message, &from) {
Ok(t) => transaction = Some(t),
Err(e) => return Box::new(future::result(Err(e))),
}
Expand Down
87 changes: 85 additions & 2 deletions client/dvm/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ pub use eth_pubsub::{EthPubSubApi, EthPubSubApiServer, HexEncodedIdProvider};
use ethereum::{
Transaction as EthereumTransaction, TransactionMessage as EthereumTransactionMessage,
};
use ethereum_types::H160;
use ethereum_types::{H160, H256};
use evm::{ExitError, ExitReason};
use jsonrpc_core::{Error, ErrorCode, Value};
pub use overrides::{OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, StorageOverride};
use sha3::{Digest, Keccak256};

pub mod frontier_backend_client {

Expand Down Expand Up @@ -257,5 +258,87 @@ pub trait EthSigner: Send + Sync {
/// Available accounts from this signer.
fn accounts(&self) -> Vec<H160>;
/// Sign a transaction message using the given account in message.
fn sign(&self, message: ethereum::TransactionMessage) -> Result<ethereum::Transaction, Error>;
fn sign(
&self,
message: ethereum::TransactionMessage,
address: &H160,
) -> Result<ethereum::Transaction, Error>;
}

pub struct EthDevSigner {
keys: Vec<secp256k1::SecretKey>,
}

impl EthDevSigner {
pub fn new() -> Self {
Self {
keys: vec![secp256k1::SecretKey::parse(&[
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11,
])
.expect("Test key is valid; qed")],
}
}
}

impl EthSigner for EthDevSigner {
fn accounts(&self) -> Vec<H160> {
self.keys
.iter()
.map(|secret| {
let public = secp256k1::PublicKey::from_secret_key(secret);
let mut res = [0u8; 64];
res.copy_from_slice(&public.serialize()[1..65]);

H160::from(H256::from_slice(Keccak256::digest(&res).as_slice()))
})
.collect()
}

fn sign(
&self,
message: ethereum::TransactionMessage,
address: &H160,
) -> Result<ethereum::Transaction, Error> {
let mut transaction = None;

for secret in &self.keys {
let key_address = {
let public = secp256k1::PublicKey::from_secret_key(secret);
let mut res = [0u8; 64];
res.copy_from_slice(&public.serialize()[1..65]);
H160::from(H256::from_slice(Keccak256::digest(&res).as_slice()))
};

if &key_address == address {
let signing_message = secp256k1::Message::parse_slice(&message.hash()[..])
.map_err(|_| internal_err("invalid signing message"))?;
let (signature, recid) = secp256k1::sign(&signing_message, secret);

let v = match message.chain_id {
None => 27 + recid.serialize() as u64,
Some(chain_id) => 2 * chain_id + 35 + recid.serialize() as u64,
};
let rs = signature.serialize();
let r = H256::from_slice(&rs[0..32]);
let s = H256::from_slice(&rs[32..64]);

transaction = Some(ethereum::Transaction {
nonce: message.nonce,
gas_price: message.gas_price,
gas_limit: message.gas_limit,
action: message.action,
value: message.value,
input: message.input.clone(),
signature: ethereum::TransactionSignature::new(v, r, s)
.ok_or(internal_err("signer generated invalid signature"))?,
});

break;
}
}

transaction.ok_or(internal_err("signer not available"))
}
}
1 change: 1 addition & 0 deletions node/rpc/src/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ where
pending_transactions.clone(),
backend.clone(),
is_authority,
Vec::new(),
max_past_logs,
)));
if let Some(filter_pool) = filter_pool {
Expand Down
18 changes: 9 additions & 9 deletions node/rpc/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ where
use substrate_frame_rpc_system::{FullSystem, SystemApi};
// --- darwinia-network ---
use dc_rpc::{
EthApi, EthApiServer, EthFilterApi, EthFilterApiServer, EthPubSubApi, EthPubSubApiServer,
HexEncodedIdProvider, NetApi, NetApiServer, OverrideHandle, RuntimeApiStorageOverride,
SchemaV1Override, StorageOverride, Web3Api, Web3ApiServer,
EthApi, EthApiServer, EthDevSigner, EthFilterApi, EthFilterApiServer, EthPubSubApi,
EthPubSubApiServer, EthSigner, HexEncodedIdProvider, NetApi, NetApiServer, OverrideHandle,
RuntimeApiStorageOverride, SchemaV1Override, StorageOverride, Web3Api, Web3ApiServer,
};
use dvm_ethereum::EthereumStorageSchema;
use template_runtime::TransactionConverter;
Expand All @@ -94,13 +94,13 @@ where
pool,
deny_unsafe,
is_authority,
enable_dev_signer,
network,
pending_transactions,
filter_pool,
command_sink,
backend,
max_past_logs,
enable_dev_signer: _,
} = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(
Expand All @@ -112,10 +112,10 @@ where
client.clone(),
)));

// let mut signers = Vec::new();
// if enable_dev_signer {
// signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);
// }
let mut signers = Vec::new();
if enable_dev_signer {
signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);
}
let mut overrides_map = BTreeMap::new();
overrides_map.insert(
EthereumStorageSchema::V1,
Expand All @@ -137,7 +137,7 @@ where
pending_transactions.clone(),
backend.clone(),
is_authority,
// signers,
signers,
max_past_logs,
)));

Expand Down
2 changes: 1 addition & 1 deletion node/runtime/template/src/pallets/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Config for Runtime {
type Lookup = AccountIdLookup<AccountId, ()>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCountForPangoro;
type BlockHashCount = BlockHashCountForPangolin;
type Version = Version;
type PalletInfo = PalletInfo;
type AccountData = AccountData<Balance>;
Expand Down
2 changes: 1 addition & 1 deletion tests/dvm/package.json → tests/dvm/darwinia/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dvm-tests",
"name": "darwinia-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/dvm/frontier/contracts/ECRecoverTests.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity 0.8.2;

contract ECRecoverTests {
function ecrecover(bytes memory input) public returns(bytes memory) {
address ecrecoverAddress = address(0x0000000000000000000000000000000000000001);
(bool success, bytes memory returnData) = ecrecoverAddress.call(input);
return returnData;
}
}
9 changes: 9 additions & 0 deletions tests/dvm/frontier/contracts/ExplicitRevertReason.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity 0.8.2;

contract ExplicitRevertReason {
function max10(uint256 a) public returns (uint256) {
if (a > 10)
revert("Value must not be greater than 10.");
return a;
}
}
14 changes: 14 additions & 0 deletions tests/dvm/frontier/contracts/Storage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity ^0.8.2;

contract Storage {
function getStorage(bytes32 key) public view returns (bytes32 value) {
assembly {
value := sload(key)
}
}
function setStorage(bytes32 key, bytes32 value) public {
assembly {
sstore(key, value)
}
}
}
16 changes: 16 additions & 0 deletions tests/dvm/frontier/contracts/Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma solidity 0.8.2;

contract Test {
function multiply(uint a) public pure returns(uint d) {
return a * 7;
}
function gasLimit() public view returns(uint) {
return block.gaslimit;
}
function currentBlock() public view returns(uint) {
return block.number;
}
function blockHash(uint number) public view returns(bytes32) {
return blockhash(number);
}
}
Loading

0 comments on commit c884a9e

Please sign in to comment.