Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
8a0bc02
create mock and testing
asiniscalchi Aug 1, 2023
0fe9a63
first test
asiniscalchi Aug 1, 2023
7ebabef
testing ethereum reserved addresses
asiniscalchi Aug 1, 2023
e964668
refactoring
asiniscalchi Aug 1, 2023
aba874e
refactoring
asiniscalchi Aug 1, 2023
80dd172
refactoring tests
asiniscalchi Aug 1, 2023
9604f6c
fmt
asiniscalchi Aug 1, 2023
390359b
erc721 starting point
asiniscalchi Aug 3, 2023
64c449a
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 3, 2023
5dafd9f
fmt
asiniscalchi Aug 3, 2023
e92faae
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 3, 2023
21d6842
Merge branch 'feature/solidity_create_collection_return_an_address' i…
asiniscalchi Aug 4, 2023
e06adce
compiling
asiniscalchi Aug 4, 2023
3869690
check selectors
asiniscalchi Aug 4, 2023
d514f88
create trait Erc721
asiniscalchi Aug 4, 2023
2efff92
Erc721Precompile
asiniscalchi Aug 4, 2023
0357938
set mocks
asiniscalchi Aug 4, 2023
cec3cbf
first implermentation
asiniscalchi Aug 4, 2023
b0c10ce
first integration of erc721 in the runtime
asiniscalchi Aug 4, 2023
1420c21
fmt
asiniscalchi Aug 4, 2023
d0c4ce7
check on the collection id
asiniscalchi Aug 4, 2023
aa84dde
test on extract owner form asset_id
asiniscalchi Aug 4, 2023
7e49dae
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 5, 2023
0ec72a7
fix tests
asiniscalchi Aug 5, 2023
9be1a5b
test for erc721 trait
asiniscalchi Aug 5, 2023
2427e0d
Merge branch 'feature/precompile_erc_721' into feature/testing_precom…
asiniscalchi Aug 5, 2023
4625aad
fix compilation
asiniscalchi Aug 5, 2023
d858bf0
refactoring
asiniscalchi Aug 5, 2023
6c65ddd
returning address
asiniscalchi Aug 6, 2023
1c9e12a
return value is correctly encoded as a n Address
asiniscalchi Aug 7, 2023
c7ec2ee
Merge branch 'bug/create_collection_logs' into feature/precompile_erc…
asiniscalchi Aug 7, 2023
c39efbd
Merge branch 'feature/testing_precompiles' into feature/precompile_er…
asiniscalchi Aug 7, 2023
9dc0c14
is_erc721_contract is not member of PrecompoileSet
asiniscalchi Aug 7, 2023
b9bba2d
test on precompiled contracts
asiniscalchi Aug 7, 2023
a39432c
erc721 returns hardcoded address
asiniscalchi Aug 7, 2023
c4cd42f
refactoring
asiniscalchi Aug 7, 2023
89af0a0
testing return of asset ownership
asiniscalchi Aug 7, 2023
c6c7810
fix errors
asiniscalchi Aug 7, 2023
5cfb2b5
remove unused use
asiniscalchi Aug 7, 2023
fa612ab
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 7, 2023
0568c47
refactoring
asiniscalchi Aug 7, 2023
b31f1db
rewriting testing mod
asiniscalchi Aug 7, 2023
9a4f100
refactoring
asiniscalchi Aug 7, 2023
09738af
moving check for cllection address in pallet
asiniscalchi Aug 8, 2023
daf2910
collection address prefix changed
asiniscalchi Aug 8, 2023
bd47de2
test passing
asiniscalchi Aug 8, 2023
907ca7e
test passing
asiniscalchi Aug 8, 2023
10557aa
refactoring tests
asiniscalchi Aug 8, 2023
6d38abe
do not panic the runtime
asiniscalchi Aug 8, 2023
daef051
fmt
asiniscalchi Aug 8, 2023
f71eef7
solidity tokenId -> _tokenId
asiniscalchi Aug 8, 2023
15123db
erc721 functions are views
asiniscalchi Aug 8, 2023
4b0ec80
update docs
asiniscalchi Aug 8, 2023
df59324
sp-core in std , removed duplicate function
asiniscalchi Aug 8, 2023
2fbd144
documentaetion
asiniscalchi Aug 8, 2023
96d7374
using compilator type ifer
asiniscalchi Aug 8, 2023
fff87c8
Minor typos corrected
tonimateos Aug 8, 2023
5bf67b0
compiler infer the size of the array
asiniscalchi Aug 8, 2023
2bf2171
added to std feature
asiniscalchi Aug 8, 2023
9e1bf8d
rename variable
asiniscalchi Aug 8, 2023
ea36349
Merge branch 'feature/precompile_erc_721' into feature/precompile_erc…
tonimateos Aug 8, 2023
bd1169b
minor extra typo
tonimateos Aug 8, 2023
713014f
Merge branch 'dev' into feature/precompile_erc_721_typos
tonimateos Aug 8, 2023
193288d
Merge branch 'dev' into feature/precompile_erc_721_typos
tonimateos Aug 11, 2023
12a3a49
Merge branch 'dev' of github.com:freeverseio/laos-ownership-node into…
magecnion Aug 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
create mock and testing
  • Loading branch information
asiniscalchi committed Aug 1, 2023
commit 8a0bc02ab49e3ef513c1f5f7dc98fd8d1fc83805
153 changes: 153 additions & 0 deletions runtime/src/precompiles/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
use frame_support::{
construct_runtime, parameter_types, sp_io,
traits::{ConstU64, FindAuthor},
weights::Weight,
};
use pallet_evm::{Config, EnsureAddressNever, EnsureAddressRoot, FeeCalculator, FixedGasWeightMapping, IdentityAddressMapping, SubstrateBlockHashMapping, runner};
use sp_core::{H160, H256, U256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup}, ConsensusEngineId,
};
use sp_std::{boxed::Box, prelude::*, str::FromStr};

use super::FrontierPrecompiles;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

// Configure a mock runtime to test the pallet.
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
Balances: pallet_balances,
Timestamp: pallet_timestamp,
LivingassetsOwnership: pallet_living_assets_ownership,
EVM: pallet_evm,
}
);

impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = H160;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}

impl pallet_balances::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Balance = u64;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type ReserveIdentifier = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
pub const MinimumPeriod: u64 = 1000;
}

impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}

impl pallet_living_assets_ownership::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CollectionId = u64;
}

pub struct FixedGasPrice;
impl FeeCalculator for FixedGasPrice {
fn min_gas_price() -> (U256, Weight) {
// Return some meaningful gas price and weight
(1_000_000_000u128.into(), Weight::from_parts(7u64, 0))
}
}
pub struct FindAuthorTruncated;
impl FindAuthor<H160> for FindAuthorTruncated {
fn find_author<'a, I>(_digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
Some(H160::from_str("1234500000000000000000000000000000000000").unwrap())
}
}

const BLOCK_GAS_LIMIT: u64 = 150_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
pub WeightPerGas: Weight = Weight::from_parts(20_000, 0);
pub PrecompilesValue: FrontierPrecompiles<Runtime> = FrontierPrecompiles::<_>::new();
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = FixedGasPrice;
type GasWeightMapping = FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type BlockHashMapping = SubstrateBlockHashMapping<Self>;
type CallOrigin = EnsureAddressRoot<Self::AccountId>;
type WithdrawOrigin = EnsureAddressNever<Self::AccountId>;
type AddressMapping = IdentityAddressMapping;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = FrontierPrecompiles<Self>;
type PrecompilesValue = PrecompilesValue;
type ChainId = ();
type BlockGasLimit = BlockGasLimit;
type Runner = runner::stack::Runner<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type Timestamp = Timestamp;
type WeightInfo = ();
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap()
.into()
}
6 changes: 6 additions & 0 deletions runtime/src/precompiles.rs → runtime/src/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ where
fn hash(a: u64) -> H160 {
H160::from_low_u64_be(a)
}

#[cfg(test)]
mod mock;

#[cfg(test)]
mod test;
8 changes: 8 additions & 0 deletions runtime/src/precompiles/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use super::mock::*;

#[test]
fn check_precompiled() {
new_test_ext().execute_with(|| {
// PrecompilesValue::is_precompile(hash(1), 0);
})
}