Skip to content

Commit abdaa73

Browse files
authored
fix: adds payable decorator to storage_unregister function (#157)
1 parent 7fc8c91 commit abdaa73

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

macros/src/standard/nep145.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub fn expand(meta: Nep145Meta) -> Result<TokenStream, darling::Error> {
115115
new_balance
116116
}
117117

118+
#[payable]
118119
fn storage_unregister(&mut self, force: Option<bool>) -> bool {
119120
use #me::standard::nep145::*;
120121
use #near_sdk::{env, Promise};

workspaces-tests/tests/fungible_token.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use near_sdk::{
44
NearToken,
55
};
66
use near_sdk_contract_tools::{
7+
ft::nep141::FtBurnData,
78
nft::StorageBalance,
89
standard::{
910
nep141::{FtTransferData, Nep141Event},
@@ -535,3 +536,34 @@ async fn transfer_call_inner_panic() {
535536
assert_eq!(ft_balance_of(&contract, bob.id()).await, 100);
536537
assert_eq!(ft_balance_of(&contract, charlie.id()).await, 10);
537538
}
539+
540+
#[tokio::test]
541+
async fn force_unregister() {
542+
let Setup {
543+
contract, accounts, ..
544+
} = setup_balances(3, |i| 10u128.pow(3 - i as u32).into()).await;
545+
let alice = &accounts[0];
546+
547+
let result = alice
548+
.call(contract.id(), "storage_unregister")
549+
.deposit(ONE_YOCTO)
550+
.args_json(json!({
551+
"force": true,
552+
}))
553+
.transact()
554+
.await
555+
.unwrap()
556+
.unwrap();
557+
558+
assert_eq!(
559+
result.logs().to_vec(),
560+
vec![Nep141Event::FtBurn(vec![FtBurnData {
561+
owner_id: alice.id().into(),
562+
amount: U128(1000),
563+
memo: Some("storage forced unregistration".into()),
564+
}])
565+
.to_event_string(),]
566+
);
567+
568+
assert_eq!(ft_balance_of(&contract, alice.id()).await, 0);
569+
}

0 commit comments

Comments
 (0)