Skip to content

Commit

Permalink
Direct unlock fails when no vesting test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Aug 30, 2022
1 parent 1aa99e9 commit 462a6e5
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions crates/humanode-runtime/src/tests/claims_and_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,53 @@ fn direct_claiming_fails_when_no_claim() {
})
}

/// This test verifies that direct unlock fails in case not existing vesting.
#[test]
fn direct_unlock_fails_when_no_vesting() {
// Build the state from the config.
new_test_ext().execute_with(move || {
// Run blocks to be vesting schedule ready.
switch_block();
set_timestamp(START_TIMESTAMP);
switch_block();

// Prepare ethereum_address and signature test data based on EIP-712 type data json.
let (ethereum_address, signature) = sign_sample_token_claim(b"Batumi", account_id("Alice"));

let total_issuance_before = Balances::total_issuance();

// Invoke the claim call for future unlocking.
assert_ok!(TokenClaims::claim(
Some(account_id("Alice")).into(),
ethereum_address,
signature
));

// Run blocks with setting proper timestamp to make full unlocking.
set_timestamp(START_TIMESTAMP + CLIFF + VESTING_DURATION);
switch_block();

// Invoke the unlock call.
assert_noop!(
Vesting::unlock(Some(account_id("Unknown")).into()),
sp_runtime::DispatchError::Module(ModuleError {
index: 28,
error: [1u8, 0u8, 0u8, 0u8],
message: Some("NoVesting")
})
);

// Ensure funds are still locked.
assert_eq!(Balances::usable_balance(account_id("Alice")), INIT_BALANCE);

// Ensure the vesting isn't gone from the state.
assert!(Vesting::locks(account_id("Alice")).is_some());

// Ensure total issuance did not change.
assert_eq!(Balances::total_issuance(), total_issuance_before);
})
}

/// This test verifies that claiming without vesting (dispatch call) works in the happy path.
#[test]
fn dispatch_claiming_without_vesting_works() {
Expand Down

0 comments on commit 462a6e5

Please sign in to comment.