Skip to content

Commit

Permalink
split up transfer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolasHaimerl committed Aug 18, 2023
1 parent 407eae6 commit 6de0417
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cycles-ledger/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{ciborium_to_generic_value, compact_account, config, endpoints::Dedup
const BLOCK_LOG_INDEX_MEMORY_ID: MemoryId = MemoryId::new(1);
const BLOCK_LOG_DATA_MEMORY_ID: MemoryId = MemoryId::new(2);
const BALANCES_MEMORY_ID: MemoryId = MemoryId::new(3);
const TRANSACTIONS_MEMORY_ID: MemoryId = MemoryId::new(4);
const TRANSACTION_MEMORY_ID: MemoryId = MemoryId::new(4);

type VMem = VirtualMemory<DefaultMemoryImpl>;

Expand Down Expand Up @@ -166,7 +166,7 @@ thread_local! {
},
blocks,
balances: Balances::init(mm.get(BALANCES_MEMORY_ID)),
transactions: TransactionsLog::init(mm.get(TRANSACTIONS_MEMORY_ID)),
transactions: TransactionsLog::init(mm.get(TRANSACTION_MEMORY_ID)),
})
});
}
Expand Down
51 changes: 50 additions & 1 deletion cycles-ledger/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ fn test_send_fails() {
}

#[test]
fn test_transfer() {
fn test_basic_transfer() {
let env = &new_state_machine();
let ledger_id = install_ledger(env);
let depositor_id = install_depositor(env, ledger_id);
Expand Down Expand Up @@ -551,6 +551,55 @@ fn test_transfer() {
)
.unwrap_err()
);
}

#[test]
fn test_deduplication() {
let env = &new_state_machine();
let ledger_id = install_ledger(env);
let depositor_id = install_depositor(env, ledger_id);
let user1 = Account {
owner: Principal::from_slice(&[1]),
subaccount: None,
};
let user2: Account = Account {
owner: Principal::from_slice(&[2]),
subaccount: None,
};
let deposit_amount = 1_000_000_000;
deposit(env, depositor_id, user1, deposit_amount);
let transfer_amount = Nat::from(100_000);

// If created_at_time is not set, the same transaction should be able to be sent multiple times
transfer(
env,
ledger_id,
user1,
TransferArg {
from_subaccount: None,
to: user2,
fee: None,
created_at_time: None,
memo: None,
amount: transfer_amount.clone(),
},
)
.unwrap();

transfer(
env,
ledger_id,
user1,
TransferArg {
from_subaccount: None,
to: user2,
fee: None,
created_at_time: None,
memo: None,
amount: transfer_amount.clone(),
},
)
.unwrap();

// Should not be able commit a transaction that was created in the future
let mut now = env
Expand Down

0 comments on commit 6de0417

Please sign in to comment.