Skip to content

Commit

Permalink
updated some fields
Browse files Browse the repository at this point in the history
  • Loading branch information
8shaks committed Jun 7, 2024
1 parent 40f844f commit 6d465df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ impl Contract {

#[payable]
pub fn initiate_claim(&mut self) -> Promise {
if(env::attached_deposit().as_yoctonear() < self.challenge_nft_ids.len().into()){
panic!("You must attach at least {} YOCTONEAR to claim the challenge", self.challenge_nft_ids.len());
}

if self.potential_winners_left == 0 {
panic!("Challenge currently at max potential winners");
}
Expand Down Expand Up @@ -382,7 +386,7 @@ impl Contract {
{
Some(message)
} else {
log!("You must grant transfer approval for the challenge NFT at index {} for us to burn it",index);
log!("Unable to park approval id for NFT at {}",index);
None
}
}
Expand Down Expand Up @@ -419,7 +423,7 @@ impl Contract {
} else {
compiled_promise.unwrap().then(
Self::ext(env::current_account_id())
.with_static_gas(Gas::from_tgas(5))
.with_static_gas(Gas::from_tgas(10))
.burn_nfts(winner_id,token_ids),
)
}
Expand Down Expand Up @@ -639,12 +643,4 @@ mod tests {
true
);
}

#[test]
#[should_panic(expected = "Challenge currently at max potential winners")]
fn initiate_claim_no_potential_winners_left() {
let mut challenge = new();
challenge.decrement_winners();
challenge.initiate_claim();
}
}
9 changes: 9 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ async fn test_complete_challenge_without_all_pieces() -> Result<(), Box<dyn std:
let outcome_with_none = user_account
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;

Expand Down Expand Up @@ -222,6 +223,7 @@ async fn test_complete_challenge_without_all_pieces() -> Result<(), Box<dyn std:
let outcome_with_some = user_account
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;
assert!(outcome_with_some
Expand Down Expand Up @@ -298,11 +300,13 @@ async fn test_complete_challenge_with_max_potential_winners(
let promise_for_account0 = user_account0
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact();

let promise_for_account1 = user_account1
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact();

let joint_promise: (
Expand Down Expand Up @@ -358,6 +362,7 @@ async fn test_complete_challenge_with_max_potential_winners(
let outcome_for_loser = loser_account
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;

Expand Down Expand Up @@ -428,6 +433,7 @@ async fn test_complete_challenge_with_already_complete() -> Result<(), Box<dyn s
let outcome_for_account0 = user_account0
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;

Expand All @@ -447,6 +453,7 @@ async fn test_complete_challenge_with_already_complete() -> Result<(), Box<dyn s
let outcome_for_account0_again = user_account0
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;

Expand All @@ -469,6 +476,7 @@ async fn test_complete_challenge_with_already_complete() -> Result<(), Box<dyn s
let outcome_for_account1 = user_account1
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;
assert!(outcome_for_account1.is_failure());
Expand Down Expand Up @@ -572,6 +580,7 @@ async fn test_mint_nft() -> Result<(), Box<dyn std::error::Error>> {
let outcome_for_account0 = user_account0
.call(challenge.contract.id(), "initiate_claim")
.max_gas()
.deposit(NearToken::from_near(1))
.transact()
.await?;

Expand Down

0 comments on commit 6d465df

Please sign in to comment.