Skip to content

Commit

Permalink
Upgrade to rc6 (ChainSafe#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhavyas authored Aug 26, 2020
1 parent 528091e commit 2773552
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 232 deletions.
418 changes: 276 additions & 142 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions chainbridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ edition = '2018'

[dependencies]
# third-party dependencies
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
serde = { version = "1.0.102", optional = true }

# primitives
sp-std = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-runtime = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-io = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-core = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-std = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
sp-runtime = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
sp-io = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
sp-core = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }

# frame dependencies
frame-support = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
frame-system = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
frame-support = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
frame-system = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }

pallet-balances = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
pallet-balances = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }

[build-dependencies]
wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68" }
wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3" }
[features]
default = ["std"]
std = [
Expand Down
14 changes: 3 additions & 11 deletions chainbridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::{
dispatch::DispatchResult,
ensure,
traits::{EnsureOrigin, Get},
weights::{FunctionOf, GetDispatchInfo, Pays},
weights::{GetDispatchInfo, Pays},
Parameter,
};

Expand Down Expand Up @@ -292,11 +292,7 @@ decl_module! {
/// # <weight>
/// - weight of proposed call, regardless of whether execution is performed
/// # </weight>
#[weight = FunctionOf(
|args: (&DepositNonce, &ChainId, &ResourceId, &Box<<T as Trait>::Proposal>)| args.3.get_dispatch_info().weight + 195_000_000,
|args: (&DepositNonce, &ChainId, &ResourceId, &Box<<T as Trait>::Proposal>)| args.3.get_dispatch_info().class,
Pays::Yes
)]
#[weight = (call.get_dispatch_info().weight + 195_000_000, call.get_dispatch_info().class, Pays::Yes)]
pub fn acknowledge_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<<T as Trait>::Proposal>) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(Self::is_relayer(&who), Error::<T>::MustBeRelayer);
Expand Down Expand Up @@ -329,11 +325,7 @@ decl_module! {
/// # <weight>
/// - weight of proposed call, regardless of whether execution is performed
/// # </weight>
#[weight = FunctionOf(
|args: (&DepositNonce, &ChainId, &Box<<T as Trait>::Proposal>)| args.2.get_dispatch_info().weight + 195_000_000,
|args: (&DepositNonce, &ChainId, &Box<<T as Trait>::Proposal>)| args.2.get_dispatch_info().class,
Pays::Yes
)]
#[weight = (prop.get_dispatch_info().weight + 195_000_000, prop.get_dispatch_info().class, Pays::Yes)]
pub fn eval_vote_state(origin, nonce: DepositNonce, src_id: ChainId, prop: Box<<T as Trait>::Proposal>) -> DispatchResult {
ensure_signed(origin)?;

Expand Down
17 changes: 10 additions & 7 deletions chainbridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ parameter_types! {
}

impl frame_system::Trait for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
Expand All @@ -45,6 +46,7 @@ impl frame_system::Trait for Test {
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

parameter_types! {
Expand All @@ -61,6 +63,7 @@ impl pallet_balances::Trait for Test {
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
}

parameter_types! {
Expand Down Expand Up @@ -121,16 +124,16 @@ pub fn new_test_ext_initialized(
let mut t = new_test_ext();
t.execute_with(|| {
// Set and check threshold
assert_ok!(Bridge::set_threshold(Origin::ROOT, TEST_THRESHOLD));
assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD));
assert_eq!(Bridge::relayer_threshold(), TEST_THRESHOLD);
// Add relayers
assert_ok!(Bridge::add_relayer(Origin::ROOT, RELAYER_A));
assert_ok!(Bridge::add_relayer(Origin::ROOT, RELAYER_B));
assert_ok!(Bridge::add_relayer(Origin::ROOT, RELAYER_C));
assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_A));
assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_B));
assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_C));
// Whitelist chain
assert_ok!(Bridge::whitelist_chain(Origin::ROOT, src_id));
assert_ok!(Bridge::whitelist_chain(Origin::root(), src_id));
// Set and check resource ID mapped to some junk data
assert_ok!(Bridge::set_resource(Origin::ROOT, r_id, resource));
assert_ok!(Bridge::set_resource(Origin::root(), r_id, resource));
assert_eq!(Bridge::resource_exists(r_id), true);
});
t
Expand Down
36 changes: 18 additions & 18 deletions chainbridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ fn setup_resources() {
let method = "Pallet.do_something".as_bytes().to_vec();
let method2 = "Pallet.do_somethingElse".as_bytes().to_vec();

assert_ok!(Bridge::set_resource(Origin::ROOT, id, method.clone()));
assert_ok!(Bridge::set_resource(Origin::root(), id, method.clone()));
assert_eq!(Bridge::resources(id), Some(method));

assert_ok!(Bridge::set_resource(Origin::ROOT, id, method2.clone()));
assert_ok!(Bridge::set_resource(Origin::root(), id, method2.clone()));
assert_eq!(Bridge::resources(id), Some(method2));

assert_ok!(Bridge::remove_resource(Origin::ROOT, id));
assert_ok!(Bridge::remove_resource(Origin::root(), id));
assert_eq!(Bridge::resources(id), None);
})
}
Expand All @@ -95,9 +95,9 @@ fn whitelist_chain() {
new_test_ext().execute_with(|| {
assert!(!Bridge::chain_whitelisted(0));

assert_ok!(Bridge::whitelist_chain(Origin::ROOT, 0));
assert_ok!(Bridge::whitelist_chain(Origin::root(), 0));
assert_noop!(
Bridge::whitelist_chain(Origin::ROOT, TestChainId::get()),
Bridge::whitelist_chain(Origin::root(), TestChainId::get()),
Error::<Test>::InvalidChainId
);

Expand All @@ -110,10 +110,10 @@ fn set_get_threshold() {
new_test_ext().execute_with(|| {
assert_eq!(<RelayerThreshold>::get(), 1);

assert_ok!(Bridge::set_threshold(Origin::ROOT, TEST_THRESHOLD));
assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD));
assert_eq!(<RelayerThreshold>::get(), TEST_THRESHOLD);

assert_ok!(Bridge::set_threshold(Origin::ROOT, 5));
assert_ok!(Bridge::set_threshold(Origin::root(), 5));
assert_eq!(<RelayerThreshold>::get(), 5);

assert_events(vec![
Expand All @@ -133,9 +133,9 @@ fn asset_transfer_success() {
let amount = 100;
let token_id = vec![1, 2, 3, 4];

assert_ok!(Bridge::set_threshold(Origin::ROOT, TEST_THRESHOLD,));
assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD,));

assert_ok!(Bridge::whitelist_chain(Origin::ROOT, dest_id.clone()));
assert_ok!(Bridge::whitelist_chain(Origin::root(), dest_id.clone()));
assert_ok!(Bridge::transfer_fungible(
dest_id.clone(),
resource_id.clone(),
Expand Down Expand Up @@ -190,7 +190,7 @@ fn asset_transfer_invalid_chain() {
let bad_dest_id = 3;
let resource_id = [4; 32];

assert_ok!(Bridge::whitelist_chain(Origin::ROOT, chain_id.clone()));
assert_ok!(Bridge::whitelist_chain(Origin::root(), chain_id.clone()));
assert_events(vec![Event::bridge(RawEvent::ChainWhitelisted(
chain_id.clone(),
))]);
Expand All @@ -215,25 +215,25 @@ fn asset_transfer_invalid_chain() {
#[test]
fn add_remove_relayer() {
new_test_ext().execute_with(|| {
assert_ok!(Bridge::set_threshold(Origin::ROOT, TEST_THRESHOLD,));
assert_ok!(Bridge::set_threshold(Origin::root(), TEST_THRESHOLD,));
assert_eq!(Bridge::relayer_count(), 0);

assert_ok!(Bridge::add_relayer(Origin::ROOT, RELAYER_A));
assert_ok!(Bridge::add_relayer(Origin::ROOT, RELAYER_B));
assert_ok!(Bridge::add_relayer(Origin::ROOT, RELAYER_C));
assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_A));
assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_B));
assert_ok!(Bridge::add_relayer(Origin::root(), RELAYER_C));
assert_eq!(Bridge::relayer_count(), 3);

// Already exists
assert_noop!(
Bridge::add_relayer(Origin::ROOT, RELAYER_A),
Bridge::add_relayer(Origin::root(), RELAYER_A),
Error::<Test>::RelayerAlreadyExists
);

// Confirm removal
assert_ok!(Bridge::remove_relayer(Origin::ROOT, RELAYER_B));
assert_ok!(Bridge::remove_relayer(Origin::root(), RELAYER_B));
assert_eq!(Bridge::relayer_count(), 2);
assert_noop!(
Bridge::remove_relayer(Origin::ROOT, RELAYER_B),
Bridge::remove_relayer(Origin::root(), RELAYER_B),
Error::<Test>::RelayerInvalid
);
assert_eq!(Bridge::relayer_count(), 2);
Expand Down Expand Up @@ -423,7 +423,7 @@ fn execute_after_threshold_change() {
assert_eq!(prop, expected);

// Change threshold
assert_ok!(Bridge::set_threshold(Origin::ROOT, 1));
assert_ok!(Bridge::set_threshold(Origin::root(), 1));

// Attempt to execute
assert_ok!(Bridge::eval_vote_state(
Expand Down
18 changes: 9 additions & 9 deletions example-erc721/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ edition = '2018'

[dependencies]
# third-party dependencies
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
serde = { version = "1.0.102", optional = true }

# primitives
sp-std = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-runtime = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-io = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-core = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
sp-std = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
sp-runtime = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
sp-io = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
sp-core = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }

# frame dependencies
frame-support = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
frame-system = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
frame-support = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }
frame-system = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }

chainbridge = { path = "../chainbridge" , default-features = false }

[dev-dependencies]
pallet-balances = { version = "2.0.0-rc3", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68", default-features = false }
pallet-balances = { version = "2.0.0-rc6", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3", default-features = false }

[build-dependencies]
wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", git = "https://github.com/paritytech/substrate.git", rev = "34695a85650b58bcd7d7e2a677cafc2921251d68" }
wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", git = "https://github.com/paritytech/substrate.git", rev = "be8bb186d87b9d2b47a2907c9b51ae1e252362c3" }
[features]
default = ["std"]
std = [
Expand Down
5 changes: 4 additions & 1 deletion example-erc721/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ parameter_types! {
}

impl frame_system::Trait for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
Expand All @@ -45,6 +46,7 @@ impl frame_system::Trait for Test {
type AccountData = balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}

parameter_types! {
Expand All @@ -61,6 +63,7 @@ impl pallet_balances::Trait for Test {
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
}

parameter_types! {
Expand Down
36 changes: 28 additions & 8 deletions example-erc721/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ fn mint_burn_tokens() {
let metadata_a: Vec<u8> = vec![1, 2, 3];
let metadata_b: Vec<u8> = vec![4, 5, 6];

assert_ok!(Erc721::mint(Origin::ROOT, USER_A, id_a, metadata_a.clone()));
assert_ok!(Erc721::mint(
Origin::root(),
USER_A,
id_a,
metadata_a.clone()
));
assert_eq!(
Erc721::tokens(id_a).unwrap(),
Erc721Token {
Expand All @@ -23,11 +28,16 @@ fn mint_burn_tokens() {
);
assert_eq!(Erc721::token_count(), 1.into());
assert_noop!(
Erc721::mint(Origin::ROOT, USER_A, id_a, metadata_a.clone()),
Erc721::mint(Origin::root(), USER_A, id_a, metadata_a.clone()),
Error::<Test>::TokenAlreadyExists
);

assert_ok!(Erc721::mint(Origin::ROOT, USER_A, id_b, metadata_b.clone()));
assert_ok!(Erc721::mint(
Origin::root(),
USER_A,
id_b,
metadata_b.clone()
));
assert_eq!(
Erc721::tokens(id_b).unwrap(),
Erc721Token {
Expand All @@ -37,16 +47,16 @@ fn mint_burn_tokens() {
);
assert_eq!(Erc721::token_count(), 2.into());
assert_noop!(
Erc721::mint(Origin::ROOT, USER_A, id_b, metadata_b.clone()),
Erc721::mint(Origin::root(), USER_A, id_b, metadata_b.clone()),
Error::<Test>::TokenAlreadyExists
);

assert_ok!(Erc721::burn(Origin::ROOT, id_a));
assert_ok!(Erc721::burn(Origin::root(), id_a));
assert_eq!(Erc721::token_count(), 1.into());
assert!(!<Tokens>::contains_key(&id_a));
assert!(!<TokenOwner<Test>>::contains_key(&id_a));

assert_ok!(Erc721::burn(Origin::ROOT, id_b));
assert_ok!(Erc721::burn(Origin::root(), id_b));
assert_eq!(Erc721::token_count(), 0.into());
assert!(!<Tokens>::contains_key(&id_b));
assert!(!<TokenOwner<Test>>::contains_key(&id_b));
Expand All @@ -61,8 +71,18 @@ fn transfer_tokens() {
let metadata_a: Vec<u8> = vec![1, 2, 3];
let metadata_b: Vec<u8> = vec![4, 5, 6];

assert_ok!(Erc721::mint(Origin::ROOT, USER_A, id_a, metadata_a.clone()));
assert_ok!(Erc721::mint(Origin::ROOT, USER_A, id_b, metadata_b.clone()));
assert_ok!(Erc721::mint(
Origin::root(),
USER_A,
id_a,
metadata_a.clone()
));
assert_ok!(Erc721::mint(
Origin::root(),
USER_A,
id_b,
metadata_b.clone()
));

assert_ok!(Erc721::transfer(Origin::signed(USER_A), USER_B, id_a));
assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B);
Expand Down
Loading

0 comments on commit 2773552

Please sign in to comment.