From a911051e90ec6aa27c9d693a3d9ce66d24baa6fe Mon Sep 17 00:00:00 2001 From: BenRey Date: Mon, 18 Mar 2024 16:11:51 +0100 Subject: [PATCH] Add test for transfercoin fail if balance undifined --- assembly/__tests__/env-coins.spec.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/assembly/__tests__/env-coins.spec.ts b/assembly/__tests__/env-coins.spec.ts index 6456e462..cea85da0 100644 --- a/assembly/__tests__/env-coins.spec.ts +++ b/assembly/__tests__/env-coins.spec.ts @@ -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( @@ -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(); @@ -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