Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit f2cce10

Browse files
authored
resourceID parametr add to example pallet calls, test update (#71)
* resourceID parametr add to example pallet calls, test update * cargo fmt
1 parent d0755a4 commit f2cce10

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

example-pallet/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,23 @@ decl_module! {
103103

104104
/// Executes a simple currency transfer using the bridge account as the source
105105
#[weight = 195_000_000]
106-
pub fn transfer(origin, to: T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
106+
pub fn transfer(origin, to: T::AccountId, amount: BalanceOf<T>, r_id: ResourceId) -> DispatchResult {
107107
let source = T::BridgeOrigin::ensure_origin(origin)?;
108108
<T as Trait>::Currency::transfer(&source, &to, amount.into(), AllowDeath)?;
109109
Ok(())
110110
}
111111

112112
/// This can be called by the bridge to demonstrate an arbitrary call from a proposal.
113113
#[weight = 195_000_000]
114-
pub fn remark(origin, hash: T::Hash) -> DispatchResult {
114+
pub fn remark(origin, hash: T::Hash, r_id: ResourceId) -> DispatchResult {
115115
T::BridgeOrigin::ensure_origin(origin)?;
116116
Self::deposit_event(RawEvent::Remark(hash));
117117
Ok(())
118118
}
119119

120120
/// Allows the bridge to issue new erc721 tokens
121121
#[weight = 195_000_000]
122-
pub fn mint_erc721(origin, recipient: T::AccountId, id: U256, metadata: Vec<u8>) -> DispatchResult {
122+
pub fn mint_erc721(origin, recipient: T::AccountId, id: U256, metadata: Vec<u8>, r_id: ResourceId) -> DispatchResult {
123123
T::BridgeOrigin::ensure_origin(origin)?;
124124
<erc721::Module<T>>::mint_token(recipient, id, metadata)?;
125125
Ok(())

example-pallet/src/tests.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ use sp_core::{blake2_256, H256};
1616
const TEST_THRESHOLD: u32 = 2;
1717

1818
fn make_remark_proposal(hash: H256) -> Call {
19-
Call::Example(crate::Call::remark(hash))
19+
let resource_id = HashId::get();
20+
Call::Example(crate::Call::remark(hash, resource_id))
2021
}
2122

2223
fn make_transfer_proposal(to: u64, amount: u64) -> Call {
23-
Call::Example(crate::Call::transfer(to, amount.into()))
24+
let resource_id = HashId::get();
25+
Call::Example(crate::Call::transfer(to, amount.into(), resource_id))
2426
}
2527

2628
#[test]
@@ -173,16 +175,20 @@ fn execute_remark() {
173175
fn execute_remark_bad_origin() {
174176
new_test_ext().execute_with(|| {
175177
let hash: H256 = "ABC".using_encoded(blake2_256).into();
176-
177-
assert_ok!(Example::remark(Origin::signed(Bridge::account_id()), hash));
178+
let resource_id = HashId::get();
179+
assert_ok!(Example::remark(
180+
Origin::signed(Bridge::account_id()),
181+
hash,
182+
resource_id
183+
));
178184
// Don't allow any signed origin except from bridge addr
179185
assert_noop!(
180-
Example::remark(Origin::signed(RELAYER_A), hash),
186+
Example::remark(Origin::signed(RELAYER_A), hash, resource_id),
181187
DispatchError::BadOrigin
182188
);
183189
// Don't allow root calls
184190
assert_noop!(
185-
Example::remark(Origin::root(), hash),
191+
Example::remark(Origin::root(), hash, resource_id),
186192
DispatchError::BadOrigin
187193
);
188194
})
@@ -193,12 +199,14 @@ fn transfer() {
193199
new_test_ext().execute_with(|| {
194200
// Check inital state
195201
let bridge_id: u64 = Bridge::account_id();
202+
let resource_id = HashId::get();
196203
assert_eq!(Balances::free_balance(&bridge_id), ENDOWED_BALANCE);
197204
// Transfer and check result
198205
assert_ok!(Example::transfer(
199206
Origin::signed(Bridge::account_id()),
200207
RELAYER_A,
201-
10
208+
10,
209+
resource_id,
202210
));
203211
assert_eq!(Balances::free_balance(&bridge_id), ENDOWED_BALANCE - 10);
204212
assert_eq!(Balances::free_balance(RELAYER_A), ENDOWED_BALANCE + 10);
@@ -218,15 +226,16 @@ fn mint_erc721() {
218226
let recipient = RELAYER_A;
219227
let metadata = vec![1, 1, 1, 1];
220228
let bridge_id: u64 = Bridge::account_id();
221-
229+
let resource_id = HashId::get();
222230
// Token doesn't yet exist
223231
assert_eq!(Erc721::tokens(token_id), None);
224232
// Mint
225233
assert_ok!(Example::mint_erc721(
226234
Origin::signed(bridge_id),
227235
recipient,
228236
token_id,
229-
metadata.clone()
237+
metadata.clone(),
238+
resource_id,
230239
));
231240
// Ensure token exists
232241
assert_eq!(
@@ -242,7 +251,8 @@ fn mint_erc721() {
242251
Origin::signed(bridge_id),
243252
recipient,
244253
token_id,
245-
metadata.clone()
254+
metadata.clone(),
255+
resource_id,
246256
),
247257
erc721::Error::<Test>::TokenAlreadyExists
248258
);

0 commit comments

Comments
 (0)