Skip to content

Commit

Permalink
add tests to cover over-funded and partial-funded renewals
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-c-child committed Jul 22, 2024
1 parent c49653e commit 687f2f7
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions contracts/name-minter/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,84 @@ mod query {
assert!(result.unwrap().is_some());
}

#[test]
fn allow_partial_funded_renewal() {
let mut app = instantiate_contracts(None, None, None);

mint_and_list(&mut app, NAME, USER, None).unwrap();

update_block_time(&mut app, SECONDS_PER_YEAR - (60 * 60 * 24 * 30));

let response = app.wrap().query_wasm_smart::<(Option<Coin>, Option<Bid>)>(
MKT,
&MarketplaceQueryMsg::AskRenewPrice {
current_time: app.block_info().time,
token_id: NAME.to_string(),
},
);
assert!(response.is_ok());
let renewal_price = response.unwrap().0.unwrap();

// try to over-fund renewal
let fund_amount = coins(renewal_price.amount.u128(), NATIVE_DENOM);
app.sudo(CwSudoMsg::Bank({
BankSudo::Mint {
to_address: USER.to_string(),
amount: fund_amount,
}
}))
.map_err(|err| println!("{:?}", err))
.ok();
let result = app.execute_contract(
Addr::unchecked(USER),
Addr::unchecked(MKT),
&MarketplaceExecuteMsg::FundRenewal {
token_id: NAME.to_string(),
},
&[coin(renewal_price.amount.u128() - 100u128, NATIVE_DENOM)],
);
assert!(result.is_ok());
}

#[test]
fn reject_overfunded_renewal() {
let mut app = instantiate_contracts(None, None, None);

mint_and_list(&mut app, NAME, USER, None).unwrap();

update_block_time(&mut app, SECONDS_PER_YEAR - (60 * 60 * 24 * 30));

let response = app.wrap().query_wasm_smart::<(Option<Coin>, Option<Bid>)>(
MKT,
&MarketplaceQueryMsg::AskRenewPrice {
current_time: app.block_info().time,
token_id: NAME.to_string(),
},
);
assert!(response.is_ok());
let renewal_price = response.unwrap().0.unwrap();

// try to over-fund renewal
let fund_amount = coins(renewal_price.amount.u128(), NATIVE_DENOM);
app.sudo(CwSudoMsg::Bank({
BankSudo::Mint {
to_address: USER.to_string(),
amount: fund_amount,
}
}))
.map_err(|err| println!("{:?}", err))
.ok();
let result = app.execute_contract(
Addr::unchecked(USER),
Addr::unchecked(MKT),
&MarketplaceExecuteMsg::FundRenewal {
token_id: NAME.to_string(),
},
&[coin(renewal_price.amount.u128() + 100u128, NATIVE_DENOM)],
);
assert!(result.is_err());
}

#[test]
fn query_name() {
let mut app = instantiate_contracts(None, None, None);
Expand Down

0 comments on commit 687f2f7

Please sign in to comment.