Skip to content

Commit

Permalink
account20
Browse files Browse the repository at this point in the history
Signed-off-by: xermicus <[email protected]>
  • Loading branch information
xermicus committed Sep 4, 2024
1 parent 9226898 commit 68b5b70
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 443 deletions.
721 changes: 373 additions & 348 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ log = { version = "0.4" }
# polkadot-sdk and friends
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.1", default-features = false }
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "1c4141abeb4c581e503f07af2a3522e6918db591" }
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "d7b575338b2c647e04fc48bfbe00ea8f492fb580" }

# llvm
[workspace.dependencies.inkwell]
Expand Down
7 changes: 3 additions & 4 deletions crates/benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ pub fn create_specs(contract: &revive_integration::cases::Contract) -> revive_ru
actions: vec![
Instantiate {
code: Code::Bytes(contract.pvm_runtime.to_vec()),
origin: TestAccountId::Alice,
origin: TestAddress::Alice,
data: Default::default(),
value: Default::default(),
gas_limit: Default::default(),
storage_deposit_limit: Default::default(),
salt: Default::default(),
},
Call {
origin: TestAccountId::Alice,
dest: TestAccountId::Instantiated(0),
origin: TestAddress::Alice,
dest: TestAddress::Instantiated(0),
data: contract.calldata.to_vec(),
value: Default::default(),
gas_limit: Default::default(),
Expand Down Expand Up @@ -59,7 +59,6 @@ pub fn measure_evm(code: &[u8], input: &[u8], iters: u64) -> std::time::Duration
let log = revive_differential::Evm::default()
.code_blob(code.as_bytes().to_vec())
.input(input.to_vec().into())
.genesis_path("/tmp/genesis.json".into())
.bench(true)
.run();
assert!(log.output.run_success(), "evm run failed: {log:?}");
Expand Down
4 changes: 2 additions & 2 deletions crates/integration/codesize.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"Baseline": 878,
"Computation": 4305,
"DivisionArithmetics": 39774,
"ERC20": 53405,
"ERC20": 46989,
"Events": 1693,
"FibonacciIterative": 2917,
"Flipper": 3570,
"SHA1": 32557
"SHA1": 32480
}
26 changes: 13 additions & 13 deletions crates/integration/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_spec!(mstore8, "MStore8", "MStore8.sol");

fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
vec![Instantiate {
origin: TestAccountId::Alice,
origin: TestAddress::Alice,
value: 0,
gas_limit: Some(GAS_LIMIT),
storage_deposit_limit: None,
Expand All @@ -47,15 +47,15 @@ fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
pipeline: None,
},
data: vec![],
salt: vec![],
salt: OptionalHex::default(),
}]
}

fn run_differential(actions: Vec<SpecsAction>) {
Specs {
differential: true,
balances: vec![(ALICE, 1_000_000_000)],
actions,
..Default::default()
}
.run();
}
Expand All @@ -80,8 +80,8 @@ fn bitwise_byte() {
])
{
actions.push(Call {
origin: TestAccountId::Alice,
dest: TestAccountId::Instantiated(0),
origin: TestAddress::Alice,
dest: TestAddress::Instantiated(0),
value: 0,
gas_limit: None,
storage_deposit_limit: None,
Expand All @@ -107,8 +107,8 @@ fn unsigned_division() {
(one, U256::ZERO),
] {
actions.push(Call {
origin: TestAccountId::Alice,
dest: TestAccountId::Instantiated(0),
origin: TestAddress::Alice,
dest: TestAddress::Instantiated(0),
value: 0,
gas_limit: None,
storage_deposit_limit: None,
Expand Down Expand Up @@ -142,8 +142,8 @@ fn signed_division() {
(one, I256::ZERO),
] {
actions.push(Call {
origin: TestAccountId::Alice,
dest: TestAccountId::Instantiated(0),
origin: TestAddress::Alice,
dest: TestAddress::Instantiated(0),
value: 0,
gas_limit: None,
storage_deposit_limit: None,
Expand Down Expand Up @@ -171,8 +171,8 @@ fn unsigned_remainder() {
(U256::MAX, U256::ZERO),
] {
actions.push(Call {
origin: TestAccountId::Alice,
dest: TestAccountId::Instantiated(0),
origin: TestAddress::Alice,
dest: TestAddress::Instantiated(0),
value: 0,
gas_limit: None,
storage_deposit_limit: None,
Expand Down Expand Up @@ -212,8 +212,8 @@ fn signed_remainder() {
(I256::ZERO, I256::ZERO),
] {
actions.push(Call {
origin: TestAccountId::Alice,
dest: TestAccountId::Instantiated(0),
origin: TestAddress::Alice,
dest: TestAddress::Instantiated(0),
value: 0,
gas_limit: None,
storage_deposit_limit: None,
Expand Down
48 changes: 25 additions & 23 deletions crates/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

use std::time::Duration;

use hex::{FromHex, FromHexError, ToHex};
use hex::{FromHex, ToHex};
use polkadot_sdk::*;
use polkadot_sdk::{
pallet_revive::{CollectEvents, ContractExecResult, ContractInstantiateResult, DebugInfo},
polkadot_runtime_common::BuildStorage,
polkadot_sdk_frame::testing_prelude::*,
sp_core::H160,
sp_keystore::{testing::MemoryKeystore, KeystoreExt},
sp_runtime::AccountId32,
};
use serde::{Deserialize, Serialize};

Expand All @@ -41,9 +43,9 @@ mod specs;
use crate::runtime::*;
pub use crate::specs::*;

pub const ALICE: AccountId = AccountId::new([1u8; 32]);
pub const BOB: AccountId = AccountId::new([2u8; 32]);
pub const CHARLIE: AccountId = AccountId::new([3u8; 32]);
pub const ALICE: H160 = H160([1u8; 20]);
pub const BOB: H160 = H160([2u8; 20]);
pub const CHARLIE: H160 = H160([3u8; 20]);

const SPEC_MARKER_BEGIN: &str = "/* runner.json";
const SPEC_MARKER_END: &str = "*/";
Expand All @@ -52,12 +54,12 @@ const SPEC_MARKER_END: &str = "*/";
#[derive(Default)]
pub struct ExtBuilder {
/// List of endowments at genesis
balance_genesis_config: Vec<(AccountId, Balance)>,
balance_genesis_config: Vec<(AccountId32, Balance)>,
}

impl ExtBuilder {
/// Set the balance of an account at genesis
fn balance_genesis_config(mut self, value: Vec<(AccountId, Balance)>) -> Self {
fn balance_genesis_config(mut self, value: Vec<(AccountId32, Balance)>) -> Self {
self.balance_genesis_config = value;
self
}
Expand Down Expand Up @@ -94,45 +96,45 @@ pub struct VerifyCallExpectation {
pub gas_consumed: Option<Weight>,
/// When provided, the expected output
#[serde(default, with = "hex")]
pub output: OptionalHex,
pub output: OptionalHex<Vec<u8>>,
///Expected call result
pub success: bool,
}

#[derive(Clone, Debug, Default, PartialEq)]
pub struct OptionalHex(Option<Vec<u8>>);
pub struct OptionalHex<T>(Option<T>);

impl FromHex for OptionalHex {
type Error = FromHexError;
impl<I: FromHex + AsRef<[u8]>> FromHex for OptionalHex<I> {
type Error = <I as FromHex>::Error;

fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let value = hex::decode(hex)?;
let value = I::from_hex(hex)?;
Ok(Self(Some(value)))
}
}

impl ToHex for &OptionalHex {
impl<I: AsRef<[u8]>> ToHex for &OptionalHex<I> {
fn encode_hex<T: std::iter::FromIterator<char>>(&self) -> T {
match self.0.as_ref() {
None => T::from_iter("".chars()),
Some(data) => T::from_iter(hex::encode(data).chars()),
Some(data) => I::encode_hex::<T>(data),
}
}

fn encode_hex_upper<T: std::iter::FromIterator<char>>(&self) -> T {
match self.0.as_ref() {
None => T::from_iter("".chars()),
Some(data) => T::from_iter(hex::encode_upper(data).chars()),
Some(data) => I::encode_hex_upper(data),
}
}
}

impl From<alloy_primitives::Bytes> for OptionalHex {
fn from(value: alloy_primitives::Bytes) -> Self {
if value.is_empty() {
impl<T: AsRef<[u8]>> From<T> for OptionalHex<T> {
fn from(value: T) -> Self {
if value.as_ref().is_empty() {
OptionalHex(None)
} else {
OptionalHex(Some(value.into()))
OptionalHex(Some(value))
}
}
}
Expand Down Expand Up @@ -172,7 +174,7 @@ pub enum CallResult {
wall_time: Duration,
},
Instantiate {
result: ContractInstantiateResult<AccountId, Balance, EventRecord>,
result: ContractInstantiateResult<Balance, EventRecord>,
wall_time: Duration,
},
}
Expand Down Expand Up @@ -232,7 +234,7 @@ impl Default for Code {
}
}

impl From<Code> for pallet_revive::Code<Hash> {
impl From<Code> for pallet_revive::Code {
fn from(val: Code) -> Self {
match val {
Code::Solidity {
Expand Down Expand Up @@ -308,15 +310,15 @@ mod tests {
use specs::SpecsAction::*;
let specs = Specs {
differential: false,
balances: vec![(ALICE, 1_000_000_000)],
balances: vec![(AccountId::to_account_id(&EHT_ALICE), 1_000_000_000)],
actions: vec![Instantiate {
origin: TestAccountId::Alice,
origin: TestAddress::Alice,
value: 0,
gas_limit: Some(GAS_LIMIT),
storage_deposit_limit: Some(DEPOSIT_LIMIT),
code: Code::Bytes(include_bytes!("../fixtures/Baseline.pvm").to_vec()),
data: vec![],
salt: vec![],
salt: OptionalHex::default(),
}],
};
specs.run();
Expand Down
10 changes: 5 additions & 5 deletions crates/runner/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use polkadot_sdk::{
};

pub type Balance = u128;
pub type AccountId = AccountId32;
pub type AccountId = pallet_revive::DefaultAddressMapper;
pub type Block = frame_system::mocking::MockBlock<Runtime>;
pub type Hash = <Runtime as frame_system::Config>::Hash;
pub type EventRecord =
Expand Down Expand Up @@ -45,7 +45,7 @@ mod runtime {
#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig)]
impl frame_system::Config for Runtime {
type Block = Block;
type AccountId = AccountId;
type AccountId = AccountId32;
type AccountData = pallet_balances::AccountData<<Runtime as pallet_balances::Config>::Balance>;
}

Expand Down Expand Up @@ -74,10 +74,10 @@ impl pallet_revive::Config for Runtime {
type ChainExtension = ();
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type AddressGenerator = pallet_revive::DefaultAddressGenerator;
type AddressMapper = AccountId;
type UnsafeUnstableInterface = UnstableInterface;
type UploadOrigin = EnsureSigned<AccountId>;
type InstantiateOrigin = EnsureSigned<AccountId>;
type UploadOrigin = EnsureSigned<AccountId32>;
type InstantiateOrigin = EnsureSigned<AccountId32>;
type Migrations = ();
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Debug = ();
Expand Down
Loading

0 comments on commit 68b5b70

Please sign in to comment.