Skip to content

Commit

Permalink
added negative tests for vote_on_disputes
Browse files Browse the repository at this point in the history
  • Loading branch information
mshankarrao committed Sep 16, 2023
1 parent c66c0b2 commit 398c88d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pallets/disputes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ pub mod pallet {
Err(Error::<T>::DisputeDoesNotExist.into())
}
})?;


//SHANKAR: This logic need to be recheck
if votes.iter().all(|v|{*v.1 == true}) {
Dispute::<T>::try_finalise_with_result(dispute_key, DisputeResult::Success)?;
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/disputes/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let initial_balance = 100_000_000_000_000u64;
System::set_block_number(1);
let _ = Tokens::deposit(CurrencyId::Native, &ALICE, initial_balance);
let _ = Tokens::deposit(CurrencyId::Native, &BOB, initial_balance);
let _ = Tokens::deposit(CurrencyId::Native, &CHARLIE, initial_balance);
});
ext
}
Expand Down
42 changes: 41 additions & 1 deletion pallets/disputes/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,44 @@ fn test_trying_to_insert_create_a_dispute_with_existing_key() {
Error::<Test>::DisputeAlreadyExists
);
});
}
}

// #[test]
// fn test_voting_on_a_dispute() {
// let mut jury_vec: BoundedVec<AccountIdOf<Test>, <mock::Test as pallet::Config>::MaxJurySize> = BoundedVec::new();
// jury_vec.try_push(*BOB);
// jury_vec.try_push(*CHARLIE);
// new_test_ext().execute_with(|| {
// Dispute::<Test>::new(10, *ALICE,jury_vec , BoundedVec::default()).expect("Creation Failed");
// assert_eq!(1, PalletDisputes::disputes(10).iter().count());
// PalletDisputes::vote_on_dispute(RuntimeOrigin::signed(*CHARLIE),10,true);
// PalletDisputes::vote_on_dispute(RuntimeOrigin::signed(*BOB),10,false);
//
// // let dispute = PalletDisputes::disputes(10).unwrap();
// // assert_eq!(&true,dispute.votes.get(&CHARLIE).unwrap())
// // assert_eq!(true,dispute.votes.get(&CHARLIE))
//
// });
// }

#[test]
fn test_voting_on_a_dispute_from_a_not_jury_account() {
let mut jury_vec: BoundedVec<AccountIdOf<Test>, <mock::Test as pallet::Config>::MaxJurySize> = BoundedVec::new();
jury_vec.try_push(*BOB);
// jury_vec.try_push(*CHARLIE);
new_test_ext().execute_with(|| {
Dispute::<Test>::new(10, *ALICE,jury_vec , BoundedVec::default()).expect("Creation Failed");
assert_noop!(PalletDisputes::vote_on_dispute(RuntimeOrigin::signed(*CHARLIE),10,true),Error::<Test>::NotAJuryAccount);
});
}

#[test]
fn test_voting_on_a_dispute_which_does_not_exists() {
let mut jury_vec: BoundedVec<AccountIdOf<Test>, <mock::Test as pallet::Config>::MaxJurySize> = BoundedVec::new();
jury_vec.try_push(*BOB);
new_test_ext().execute_with(|| {
Dispute::<Test>::new(10, *ALICE,jury_vec , BoundedVec::default()).expect("Creation Failed");
assert_noop!(PalletDisputes::vote_on_dispute(RuntimeOrigin::signed(*CHARLIE),1,true),Error::<Test>::DisputeDoesNotExist);
});
}

0 comments on commit 398c88d

Please sign in to comment.