Skip to content

Commit 4ffb32b

Browse files
committed
fix: tests check fee spending by balance difference
1 parent c15369c commit 4ffb32b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/integration/module.test.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ describe('@tetherto/wdk-wallet-tron', () => {
5353
value: 1_000_000
5454
}
5555

56-
await account0.quoteSendTransaction(TRANSACTION)
56+
const { fee: estimatedFee } = await account0.quoteSendTransaction(TRANSACTION)
5757

58-
const { hash } = await account0.sendTransaction(TRANSACTION)
58+
const { hash, fee } = await account0.sendTransaction(TRANSACTION)
5959

60-
await waitForTx(account0, hash)
60+
const receipt = await waitForTx(account0, hash)
61+
const actualFee = BigInt(receipt.fee || 0)
6162

6263
const onChainTx = await setup.tronWebProvider.trx.getTransaction(hash)
6364
const contract = onChainTx.raw_data.contract[0]
@@ -66,26 +67,32 @@ describe('@tetherto/wdk-wallet-tron', () => {
6667
expect(contract.type).toBe('TransferContract')
6768
expect(contract.parameter.value.amount).toBe(TRANSACTION.value)
6869
expect(setup.tronWebProvider.address.fromHex(contract.parameter.value.to_address)).toBe(RECIPIENT_ADDRESS)
70+
71+
expect(estimatedFee).toBe(actualFee)
72+
expect(fee).toBe(actualFee)
6973
}, TIMEOUT)
7074

7175
test('should derive two accounts, send a tx from account 0 to 1 and get the correct balances', async () => {
7276
const account0 = await walletManager.getAccount(0)
7377
const account1 = await walletManager.getAccount(1)
7478
const account1Address = await account1.getAddress()
7579

80+
const balance0Before = await account0.getBalance()
7681
const balance1Before = await account1.getBalance()
7782

7883
const amountSun = 1_000_000n
7984

80-
const { hash } = await account0.sendTransaction({
85+
const { hash, fee } = await account0.sendTransaction({
8186
to: account1Address,
8287
value: amountSun
8388
})
8489

8590
await waitForTx(account0, hash)
8691

92+
const balance0After = await account0.getBalance()
8793
const balance1After = await account1.getBalance()
8894

95+
expect(balance0After).toBe(balance0Before - amountSun - fee)
8996
expect(balance1After).toBe(balance1Before + amountSun)
9097
}, TIMEOUT)
9198

@@ -125,6 +132,7 @@ describe('@tetherto/wdk-wallet-tron', () => {
125132

126133
const tokenContract = await setup.genesisTronWeb.contract().at(setup.testTokenAddress)
127134

135+
const trxBefore = await account0.getBalance()
128136
const balance0Before = await account0.getTokenBalance(setup.testTokenAddress)
129137
const recipientBalanceBefore = BigInt(await tokenContract.balanceOf(RECIPIENT_ADDRESS).call())
130138

@@ -136,11 +144,14 @@ describe('@tetherto/wdk-wallet-tron', () => {
136144
amount: transferAmount
137145
})
138146

139-
await waitForTx(account0, hash)
147+
const receipt = await waitForTx(account0, hash)
148+
const actualFee = BigInt(receipt.fee || 0)
140149

150+
const trxAfter = await account0.getBalance()
141151
const balance0After = await account0.getTokenBalance(setup.testTokenAddress)
142152
const recipientBalanceAfter = BigInt(await tokenContract.balanceOf(RECIPIENT_ADDRESS).call())
143153

154+
expect(trxAfter).toBe(trxBefore - actualFee)
144155
expect(balance0After).toBe(balance0Before - transferAmount)
145156
expect(recipientBalanceAfter).toBe(recipientBalanceBefore + transferAmount)
146157
}, TIMEOUT)

0 commit comments

Comments
 (0)