Skip to content

Commit 11dcac7

Browse files
committed
fix: fix balance tests
1 parent 4157306 commit 11dcac7

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

packages/neuron-wallet/tests/database/address/balance.test.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ describe('balance', () => {
1818
await connection.synchronize()
1919
})
2020

21-
const generateAddress = (liveBalance: string | bigint, sentBalance: string | bigint, pendingBalance: string | bigint) => {
21+
const generateAddress = (
22+
liveBalance: string | bigint,
23+
sentBalance: string | bigint,
24+
pendingBalance: string | bigint
25+
) => {
2226
const addr = Math.round(Math.random() * 100000000).toString()
2327
const address: Address = {
2428
walletId: '1',
@@ -31,6 +35,7 @@ describe('balance', () => {
3135
sentBalance: sentBalance.toString(),
3236
pendingBalance: pendingBalance.toString(),
3337
balance: '0',
38+
totalBalance: '0',
3439
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
3540
version: AddressVersion.Testnet,
3641
}
@@ -53,15 +58,10 @@ describe('balance', () => {
5358

5459
it('sent to others', async () => {
5560
// have 1000, sent to others 200, and refund 800
56-
const addresses = [
57-
generateAddress('0', '0', '1000'),
58-
generateAddress('0', '800', '0'),
59-
]
61+
const addresses = [generateAddress('0', '0', '1000'), generateAddress('0', '800', '0')]
6062

6163
const addrs: AddressEntity[] = await AddressDao.create(addresses)
62-
const balance: bigint = addrs
63-
.map(addr => BigInt(addr.balance()))
64-
.reduce((result, c) => result + c, BigInt(0))
64+
const balance: bigint = addrs.map(addr => BigInt(addr.balance())).reduce((result, c) => result + c, BigInt(0))
6565

6666
expect(balance).toEqual(BigInt(800))
6767
})
@@ -74,24 +74,17 @@ describe('balance', () => {
7474
generateAddress('0', '800', '0'),
7575
]
7676
const addrs: AddressEntity[] = await AddressDao.create(addresses)
77-
const balance: bigint = addrs
78-
.map(addr => BigInt(addr.balance()))
79-
.reduce((result, c) => result + c, BigInt(0))
77+
const balance: bigint = addrs.map(addr => BigInt(addr.balance())).reduce((result, c) => result + c, BigInt(0))
8078

8179
expect(balance).toEqual(BigInt(1000))
8280
})
8381

8482
it('sent to others with 10 shannon fee', async () => {
8583
// have 1000, sent to others 200, and refund 790, with 10 shannon fee
86-
const addresses = [
87-
generateAddress('0', '0', '1000'),
88-
generateAddress('0', '790', '0'),
89-
]
84+
const addresses = [generateAddress('0', '0', '1000'), generateAddress('0', '790', '0')]
9085

9186
const addrs: AddressEntity[] = await AddressDao.create(addresses)
92-
const balance: bigint = addrs
93-
.map(addr => BigInt(addr.balance()))
94-
.reduce((result, c) => result + c, BigInt(0))
87+
const balance: bigint = addrs.map(addr => BigInt(addr.balance())).reduce((result, c) => result + c, BigInt(0))
9588

9689
expect(balance).toEqual(BigInt(790))
9790
})
@@ -105,9 +98,7 @@ describe('balance', () => {
10598
]
10699

107100
const addrs: AddressEntity[] = await AddressDao.create(addresses)
108-
const balance: bigint = addrs
109-
.map(addr => BigInt(addr.balance()))
110-
.reduce((result, c) => result + c, BigInt(0))
101+
const balance: bigint = addrs.map(addr => BigInt(addr.balance())).reduce((result, c) => result + c, BigInt(0))
111102

112103
expect(balance).toEqual(BigInt(990))
113104
})

0 commit comments

Comments
 (0)