Skip to content

Commit

Permalink
Merge branch 'daan/fix-read_state_error_handling' into daan/feat-asse…
Browse files Browse the repository at this point in the history
…t_management
  • Loading branch information
Daanvdplas committed Jul 31, 2024
2 parents 602b8bf + 51c38cc commit 406063c
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions pop-api/integration-tests/src/local_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,21 +532,17 @@ fn total_supply(addr: AccountId32, asset_id: AssetId) -> Result<Balance, Error>
let function = function_selector("total_supply");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<Balance, Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<Balance, Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

// Call balance_of contract message.
fn balance_of(addr: AccountId32, asset_id: AssetId, owner: AccountId32) -> Result<Balance, Error> {
let function = function_selector("balance_of");
let params = [function, asset_id.encode(), owner.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<Balance, Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<Balance, Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

// Call allowance contract message.
Expand All @@ -559,43 +555,35 @@ fn allowance(
let function = function_selector("allowance");
let params = [function, asset_id.encode(), owner.encode(), spender.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<Balance, Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<Balance, Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

// Call token_name contract message.
fn token_name(addr: AccountId32, asset_id: AssetId) -> Result<Vec<u8>, Error> {
let function = function_selector("token_name");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<Vec<u8>, Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<Vec<u8>, Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

// Call token_symbol contract message.
fn token_symbol(addr: AccountId32, asset_id: AssetId) -> Result<Vec<u8>, Error> {
let function = function_selector("token_symbol");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<Vec<u8>, Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<Vec<u8>, Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

// Call token_decimals contract message.
fn token_decimals(addr: AccountId32, asset_id: AssetId) -> Result<u8, Error> {
let function = function_selector("token_decimals");
let params = [function, asset_id.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<u8, Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<u8, Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

fn transfer(
Expand All @@ -607,10 +595,8 @@ fn transfer(
let function = function_selector("transfer");
let params = [function, asset_id.encode(), to.encode(), value.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<(), Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<(), Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

fn transfer_from(
Expand All @@ -626,10 +612,8 @@ fn transfer_from(
[function, asset_id.encode(), from.encode(), to.encode(), value.encode(), data.encode()]
.concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<(), Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<(), Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

fn approve(
Expand All @@ -641,10 +625,8 @@ fn approve(
let function = function_selector("approve");
let params = [function, asset_id.encode(), spender.encode(), value.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<(), Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<(), Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

fn increase_allowance(
Expand All @@ -656,10 +638,8 @@ fn increase_allowance(
let function = function_selector("increase_allowance");
let params = [function, asset_id.encode(), spender.encode(), value.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<(), Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<(), Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

fn decrease_allowance(
Expand All @@ -671,10 +651,8 @@ fn decrease_allowance(
let function = function_selector("decrease_allowance");
let params = [function, asset_id.encode(), spender.encode(), value.encode()].concat();
let result = bare_call(addr, params, 0).expect("should work");
match decoded::<Result<(), Error>>(result) {
Ok(x) => x,
Err(result) => panic!("Contract reverted: {:?}", result),
}
decoded::<Result<(), Error>>(result.clone())
.unwrap_or_else(|_| panic!("Contract reverted: {:?}", result))
}

fn create(
Expand Down

0 comments on commit 406063c

Please sign in to comment.