This repository was archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbalance.test.ts
55 lines (47 loc) · 1.94 KB
/
balance.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Contract, JWKInterface } from 'warp-contracts';
import { IOState } from '../src/types';
import { getLocalArNSContractKey, getLocalWallet } from './utils/helper';
import { arweave, warp } from './utils/services';
describe('Balance', () => {
let contract: Contract<IOState>;
let srcContractId: string;
let nonContractOwner: JWKInterface;
let prevState: IOState;
beforeAll(async () => {
srcContractId = getLocalArNSContractKey('id');
nonContractOwner = getLocalWallet(1);
contract = warp.contract<IOState>(srcContractId).connect(nonContractOwner);
});
beforeEach(async () => {
// tick so we are always working off freshest state
await contract.writeInteraction({ function: 'tick' });
prevState = (await contract.readState()).cachedValue.state;
});
describe('non-contract owner', () => {
it('should able to retrieve its own balance', async () => {
const nonContractOwnerAddress = await arweave.wallets.getAddress(
nonContractOwner,
);
const prevNonOwnerBalance = prevState.balances[nonContractOwnerAddress];
const { result } = (await contract.viewState({
function: 'balance',
target: nonContractOwnerAddress,
})) as any;
expect(result).not.toBe(undefined);
expect(result.target).toEqual(nonContractOwnerAddress);
expect(result.balance).toEqual(prevNonOwnerBalance);
});
it('should able to retrieve another wallets balance', async () => {
const otherWallet = getLocalWallet(2);
const otherWalletAddress = await arweave.wallets.getAddress(otherWallet);
const prevNonOwnerBalance = prevState.balances[otherWalletAddress];
const { result } = (await contract.viewState({
function: 'balance',
target: otherWalletAddress,
})) as any;
expect(result).not.toBe(undefined);
expect(result.target).toEqual(otherWalletAddress);
expect(result.balance).toEqual(prevNonOwnerBalance);
});
});
});