Skip to content

Commit 76080ba

Browse files
committed
refactor: call_with_address
1 parent 3e1b812 commit 76080ba

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

pop-api/examples/nonfungibles/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pop-api = { path = "../../../pop-api", default-features = false, features = [
1111
] }
1212

1313
[dev-dependencies]
14-
drink = { package = "pop-drink", git = "https://github.com/r0gue-io/pop-drink", branch = "chungquantin/feat-nfts", features = [ "devnet" ] }
14+
drink = { package = "pop-drink", git = "https://github.com/r0gue-io/pop-drink", branch = "chungquantin/feat-call_with_address", features = [ "devnet" ] }
1515
env_logger = { version = "0.11.3" }
1616
pallet-nfts = { git = "https://github.com/r0gue-io/pop-node" }
1717
serde_json = "1.0.114"

pop-api/examples/nonfungibles/tests.rs

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use drink::{
2-
assert_err, assert_last_contract_event, assert_ok, call,
2+
assert_err, assert_last_contract_event, assert_ok, call_with_address,
33
devnet::{
44
account_id_from_slice,
55
error::{v0::Error, Nfts, NftsError::*},
@@ -11,6 +11,9 @@ use drink::{
1111
};
1212
use pop_api::v0::nonfungibles::{events::Transfer, CollectionId, ItemId};
1313

14+
#[cfg(debug_assertions)]
15+
compile_error!("Tests must be run using the release profile (--release)");
16+
1417
use super::*;
1518

1619
const UNIT: Balance = 10_000_000_000;
@@ -331,7 +334,7 @@ fn transfer_fails_with_invalid_item(mut session: Session) {
331334
#[drink::test(sandbox = Pop)]
332335
fn destroy_works(mut session: Session) {
333336
// Deploys a new contract.
334-
let contract = Contract::new(&mut session, None, NO_SALT).unwrap();
337+
assert_ok!(Contract::new(&mut session, None, NO_SALT));
335338
// Successfully destroys a collection.
336339
session.set_gas_limit(Weight::MAX);
337340
let witness_string =
@@ -377,6 +380,7 @@ fn destroy_fails_with_bad_witness(mut session: Session) {
377380

378381
// A set of helper methods to test the contract deployment and calls.
379382

383+
#[derive(Debug)]
380384
struct Contract {
381385
pub address: AccountId,
382386
}
@@ -403,20 +407,42 @@ impl Contract {
403407
}
404408

405409
fn collection_id(&self, session: &mut Session<Pop>) -> CollectionId {
406-
call::<Pop, CollectionId, Psp34Error>(session, "collection_id", vec![], None).unwrap()
410+
call_with_address::<Pop, CollectionId, Psp34Error>(
411+
session,
412+
self.address.clone(),
413+
"collection_id",
414+
vec![],
415+
None,
416+
)
417+
.unwrap()
407418
}
408419

409420
fn next_item_id(&self, session: &mut Session<Pop>) -> ItemId {
410-
call::<Pop, ItemId, Psp34Error>(session, "next_item_id", vec![], None).unwrap()
421+
call_with_address::<Pop, ItemId, Psp34Error>(
422+
session,
423+
self.address.clone(),
424+
"next_item_id",
425+
vec![],
426+
None,
427+
)
428+
.unwrap()
411429
}
412430

413431
fn balance_of(&self, session: &mut Session<Pop>, owner: AccountId) -> u32 {
414-
call::<Pop, u32, Psp34Error>(session, "balance_of", vec![owner.to_string()], None).unwrap()
432+
call_with_address::<Pop, u32, Psp34Error>(
433+
session,
434+
self.address.clone(),
435+
"balance_of",
436+
vec![owner.to_string()],
437+
None,
438+
)
439+
.unwrap()
415440
}
416441

417442
fn owner_of(&self, session: &mut Session<Pop>, item: ItemId) -> Option<AccountId> {
418-
call::<Pop, Option<AccountId>, Psp34Error>(
443+
call_with_address::<Pop, Option<AccountId>, Psp34Error>(
419444
session,
445+
self.address.clone(),
420446
"owner_of",
421447
vec![item.to_string()],
422448
None,
@@ -425,20 +451,40 @@ impl Contract {
425451
}
426452

427453
fn total_supply(&self, session: &mut Session<Pop>) -> u128 {
428-
call::<Pop, u128, Psp34Error>(session, "total_supply", vec![], None).unwrap()
454+
call_with_address::<Pop, u128, Psp34Error>(
455+
session,
456+
self.address.clone(),
457+
"total_supply",
458+
vec![],
459+
None,
460+
)
461+
.unwrap()
429462
}
430463

431464
fn mint(&self, session: &mut Session<Pop>, to: AccountId) -> Result<()> {
432-
call::<Pop, (), Psp34Error>(session, "mint", vec![to.to_string()], None)
465+
call_with_address::<Pop, (), Psp34Error>(
466+
session,
467+
self.address.clone(),
468+
"mint",
469+
vec![to.to_string()],
470+
None,
471+
)
433472
}
434473

435474
fn burn(&self, session: &mut Session<Pop>, item: ItemId) -> Result<()> {
436-
call::<Pop, (), Psp34Error>(session, "burn", vec![item.to_string()], None)
475+
call_with_address::<Pop, (), Psp34Error>(
476+
session,
477+
self.address.clone(),
478+
"burn",
479+
vec![item.to_string()],
480+
None,
481+
)
437482
}
438483

439484
fn transfer(&self, session: &mut Session<Pop>, to: AccountId, item: ItemId) -> Result<()> {
440-
call::<Pop, (), Psp34Error>(
485+
call_with_address::<Pop, (), Psp34Error>(
441486
session,
487+
self.address.clone(),
442488
"transfer",
443489
vec![to.to_string(), item.to_string()],
444490
None,
@@ -447,6 +493,12 @@ impl Contract {
447493

448494
fn destroy(&self, session: &mut Session<Pop>, witness: DestroyWitness) -> Result<()> {
449495
let witness_string = format!("{:?}", witness);
450-
call::<Pop, (), Psp34Error>(session, "destroy", vec![witness_string], None)
496+
call_with_address::<Pop, (), Psp34Error>(
497+
session,
498+
self.address.clone(),
499+
"destroy",
500+
vec![witness_string],
501+
None,
502+
)
451503
}
452504
}

0 commit comments

Comments
 (0)