Skip to content

Commit

Permalink
Add test for transfercoin fail if balance undifined
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Mar 18, 2024
1 parent 12b2fd6 commit a911051
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion assembly/__tests__/env-coins.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// This file is aim to test the env coins related functions which are external functions

import { env } from '../env';
import { resetStorage, mockTransferredCoins } from '../vm-mock';
import {
resetStorage,
mockTransferredCoins,
addAddressToLedger,
} from '../vm-mock';
import { Address } from '../std';

const testAddress = new Address(
Expand All @@ -12,6 +16,10 @@ const testAddress2 = new Address(
'AU12E6N5BFAdC2wyiBV6VJjqkWhpz1kLVp2XpbRdSnL1mKjCWT6oT',
);

const testAddress3 = new Address(
'AU12E6N5BFAdC2wyiBV6VJjqkWhpz1kLVp2XpbRdSnL1mKjCWT6oU',
);

beforeEach(() => {
// We set the balance of the current contract to 100000 in the resetStorage
resetStorage();
Expand Down Expand Up @@ -52,6 +60,18 @@ describe('Testing env coins related functions', () => {
expect(env.balanceOf(testAddress2.toString())).toBe(amount);
});

it('transferCoins to mock address created with addAddressToLedger', () => {
addAddressToLedger(testAddress3.toString());
const amount: u64 = 100;
const receiverCurrentBalance = env.balanceOf(testAddress3.toString());
// given
expect(receiverCurrentBalance).toBe(0);
// when
env.transferCoins(testAddress3.toString(), amount);
// then
expect(env.balanceOf(testAddress3.toString())).toBe(amount);
});

it('get the balance of an address', () => {
const amount: u64 = 100;
// given
Expand Down

0 comments on commit a911051

Please sign in to comment.