Skip to content

Commit

Permalink
Refactored for new rust version
Browse files Browse the repository at this point in the history
  • Loading branch information
shanev committed Aug 8, 2023
1 parent 91d4938 commit 68eaada
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
34 changes: 17 additions & 17 deletions contracts/fair-burn/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn execute_fair_burn(
k if k == fair_burn_pool_key => {
let mut event = Event::new("fund-fair-burn-pool");
for (idx, c) in funds.iter().enumerate() {
event = event.add_attribute(format!("coin_{0}", idx), c.to_string());
event = event.add_attribute(format!("coin_{idx}"), c.to_string());
}
response = response
.add_event(event)
Expand Down Expand Up @@ -214,7 +214,7 @@ mod tests {
app.sudo(CwSudoMsg::Bank({
BankSudo::Mint {
to_address: addr.to_string(),
amount: balances.clone(),
amount: balances,
}
}))
.unwrap();
Expand Down Expand Up @@ -263,7 +263,7 @@ mod tests {
let creator = Addr::unchecked("creator");

let fee_bps = 5000;
let init_msg = InstantiateMsg { fee_bps: fee_bps };
let init_msg = InstantiateMsg { fee_bps };
let fair_burn = app
.instantiate_contract(fair_burn_id, creator, &init_msg, &[], "FairBurn", None)
.unwrap();
Expand Down Expand Up @@ -322,7 +322,7 @@ mod tests {
burner.clone(),
fair_burn.clone(),
&ExecuteMsg::FairBurn { recipient: None },
&vec![],
&[],
);
assert!(response.is_err());

Expand All @@ -331,7 +331,7 @@ mod tests {
burner.clone(),
fair_burn.clone(),
&ExecuteMsg::FairBurn { recipient: None },
&vec![coin(0, NATIVE_DENOM)],
&[coin(0, NATIVE_DENOM)],
);
assert!(response.is_err());

Expand All @@ -341,7 +341,7 @@ mod tests {
burner.clone(),
fair_burn.clone(),
&ExecuteMsg::FairBurn { recipient: None },
&vec![coin(1, NATIVE_DENOM)],
&[coin(1, NATIVE_DENOM)],
)
.unwrap();
let event = find_event(&response, "wasm-fair-burn").unwrap();
Expand All @@ -354,21 +354,21 @@ mod tests {
burner.clone(),
fair_burn.clone(),
&ExecuteMsg::FairBurn { recipient: None },
&vec![coin(1, NATIVE_DENOM), coin(1, NATIVE_DENOM)],
&[coin(1, NATIVE_DENOM), coin(1, NATIVE_DENOM)],
)
.unwrap();
let event = find_event(&response, "wasm-fair-burn").unwrap();
let burn_amount = find_attribute(event, "burn_amount").unwrap();
assert_eq!(burn_amount, "1");
println!("{:?}", response);
println!("{response:?}");

// Fees are calculated correctly
let response = app
.execute_contract(
burner.clone(),
fair_burn.clone(),
&ExecuteMsg::FairBurn { recipient: None },
&vec![coin(11, NATIVE_DENOM)],
&[coin(11, NATIVE_DENOM)],
)
.unwrap();
let event = find_event(&response, "wasm-fair-burn").unwrap();
Expand All @@ -383,7 +383,7 @@ mod tests {
burner.clone(),
fair_burn.clone(),
&ExecuteMsg::FairBurn { recipient: None },
&vec![coin(11, NATIVE_DENOM), coin(11, alt_denom)],
&[coin(11, NATIVE_DENOM), coin(11, alt_denom)],
)
.unwrap();
let event = find_event(&response, "wasm-fair-burn").unwrap();
Expand All @@ -393,7 +393,7 @@ mod tests {
assert_eq!(dist_amount, "5");
let event = find_event(&response, "wasm-fund-fair-burn-pool").unwrap();
let fair_burn_coin = find_attribute(event, "coin_0").unwrap();
assert_eq!(fair_burn_coin, format!("11{0}", alt_denom));
assert_eq!(fair_burn_coin, format!("11{alt_denom}"));

// Can handle recipient address on native denom
let response = app
Expand All @@ -403,7 +403,7 @@ mod tests {
&ExecuteMsg::FairBurn {
recipient: Some(recipient.to_string()),
},
&vec![coin(11, NATIVE_DENOM)],
&[coin(11, NATIVE_DENOM)],
)
.unwrap();
let event = find_event(&response, "wasm-fair-burn").unwrap();
Expand All @@ -413,26 +413,26 @@ mod tests {
let recipient_address = find_attribute(event, "recipient").unwrap();
assert_eq!(recipient_address, recipient.to_string());
let recipient_coin = find_attribute(event, "amount").unwrap();
assert_eq!(recipient_coin, format!("5{0}", NATIVE_DENOM));
assert_eq!(recipient_coin, format!("5{NATIVE_DENOM}"));

// Can handle recipient address on alt denom
let response = app
.execute_contract(
burner.clone(),
fair_burn.clone(),
fair_burn,
&ExecuteMsg::FairBurn {
recipient: Some(recipient.to_string()),
},
&vec![coin(11, alt_denom)],
&[coin(11, alt_denom)],
)
.unwrap();
let event = find_event(&response, "wasm-fund-fair-burn-pool").unwrap();
let fund_pool_coin = find_attribute(event, "coin_0").unwrap();
assert_eq!(fund_pool_coin, format!("6{0}", alt_denom));
assert_eq!(fund_pool_coin, format!("6{alt_denom}"));
let event = find_event(&response, "transfer").unwrap();
let recipient_address = find_attribute(event, "recipient").unwrap();
assert_eq!(recipient_address, recipient.to_string());
let recipient_coin = find_attribute(event, "amount").unwrap();
assert_eq!(recipient_coin, format!("5{0}", alt_denom));
assert_eq!(recipient_coin, format!("5{alt_denom}"));
}
}
2 changes: 1 addition & 1 deletion test/e2e/src/helpers/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn instantiate_fair_burn(
) -> Result<InstantiateResponse, ProcessError> {
orc.instantiate(
NAME_FAIR_BURN,
&format!("{}_inst", NAME_FAIR_BURN,),
&format!("{NAME_FAIR_BURN}_inst",),
&FairBurnInstantiateMsg { fee_bps: 5000 },
&user.key,
Some(user.account.address.parse().unwrap()),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/src/tests/fair_burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ fn test_fair_burn(chain: &mut Chain) {
.orc
.execute_batch("fair-burn", reqs, &master_account.key);

println!("exec_response: {:?}", exec_response);
println!("exec_response: {exec_response:?}");
assert!(exec_response.is_ok());
}

0 comments on commit 68eaada

Please sign in to comment.