Skip to content

Commit 97a6a5f

Browse files
committed
Attempt at update curve tests
1 parent 6af1715 commit 97a6a5f

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

contracts/external/cw-abc/src/test_tube/integration_tests.rs

+95-1
Original file line numberDiff line numberDiff line change
@@ -417,5 +417,99 @@ fn test_close_curve() {
417417
.unwrap();
418418
}
419419

420+
// TODO maybe we don't allow for updating the curve in the MVP as it could lead
421+
// to weird edge cases?
420422
#[test]
421-
fn test_update_curve() {}
423+
fn test_update_curve() {
424+
let app = OsmosisTestApp::new();
425+
let builder = TestEnvBuilder::new();
426+
let env = builder.default_setup(&app);
427+
let TestEnv {
428+
ref abc,
429+
ref accounts,
430+
ref tf_issuer,
431+
..
432+
} = env;
433+
434+
// Query denom
435+
let denom = tf_issuer
436+
.query::<DenomResponse>(&IssuerQueryMsg::Denom {})
437+
.unwrap()
438+
.denom;
439+
440+
// Buy enough tokens to end the hatch phase
441+
abc.execute(&ExecuteMsg::Buy {}, &coins(1000000, RESERVE), &accounts[0])
442+
.unwrap();
443+
444+
// Only owner can update the curve
445+
let err = abc
446+
.execute(
447+
&ExecuteMsg::UpdateCurve {
448+
curve_type: CurveType::Linear {
449+
slope: Uint128::new(2),
450+
scale: 5,
451+
},
452+
},
453+
&[],
454+
&accounts[1],
455+
)
456+
.unwrap_err();
457+
assert_eq!(
458+
err,
459+
abc.execute_error(ContractError::Ownership(
460+
cw_ownable::OwnershipError::NotOwner
461+
))
462+
);
463+
464+
// Owner updates curve
465+
abc.execute(
466+
&ExecuteMsg::UpdateCurve {
467+
curve_type: CurveType::Linear {
468+
slope: Uint128::new(2),
469+
scale: 5,
470+
},
471+
},
472+
&[],
473+
&accounts[0],
474+
)
475+
.unwrap();
476+
477+
// All tokens are sold successfully
478+
let user_balance = env
479+
.bank()
480+
.query_balance(&QueryBalanceRequest {
481+
address: accounts[0].address(),
482+
denom: denom.clone(),
483+
})
484+
.unwrap();
485+
assert_eq!(
486+
user_balance.balance,
487+
Some(Coin {
488+
denom: denom.clone(),
489+
amount: "9000000".to_string(),
490+
})
491+
);
492+
493+
abc.execute(
494+
&ExecuteMsg::Sell {},
495+
&coins(9000000, denom.clone()),
496+
&accounts[0],
497+
)
498+
.unwrap();
499+
500+
// No money is left over in the contract
501+
let contract_balance = env
502+
.bank()
503+
.query_balance(&QueryBalanceRequest {
504+
address: abc.contract_addr.to_string(),
505+
denom: RESERVE.to_string(),
506+
})
507+
.unwrap();
508+
assert_eq!(
509+
contract_balance.balance,
510+
Some(Coin {
511+
denom: RESERVE.to_string(),
512+
amount: "0".to_string(),
513+
})
514+
);
515+
}

0 commit comments

Comments
 (0)