-
Notifications
You must be signed in to change notification settings - Fork 6
/
ante-fees.test.js
74 lines (64 loc) · 2.31 KB
/
ante-fees.test.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import test from 'ava';
import { CHAINID, GOV1ADDR, GOV2ADDR, agd } from '@agoric/synthetic-chain';
test(`ante handler sends fee only to vbank/reserve`, async t => {
const [feeCollector, vbankReserve] = await Promise.all(
// Look up addresses for fee collector and reserve accounts.
['fee_collector', 'vbank/reserve'].map(async name => {
const {
account: {
'@type': moduleAcct,
base_account: { address },
},
} = await agd.query('auth', 'module-account', name);
t.is(
moduleAcct,
'/cosmos.auth.v1beta1.ModuleAccount',
`${name} is a module account`,
);
return address;
}),
);
const getBalances = addresses =>
Promise.all(
addresses.map(async address => {
const { balances } = await agd.query('bank', 'balances', address);
return balances;
}),
);
const [feeCollectorStartBalances, vbankReserveStartBalances] =
await getBalances([feeCollector, vbankReserve]);
// Send a transaction with a known fee.
const feeAmount = 999n;
const feeDenom = 'uist';
const result = await agd.tx(
`bank send ${GOV1ADDR} ${GOV2ADDR} 1234ubld --fees=${feeAmount}${feeDenom} \
--from=${GOV1ADDR} --chain-id=${CHAINID} --keyring-backend=test --yes`,
);
t.like(result, { code: 0 });
const [feeCollectorEndBalances, vbankReserveEndBalances] = await getBalances([
feeCollector,
vbankReserve,
]);
t.deepEqual(feeCollectorEndBalances, feeCollectorStartBalances);
// The reserve balances should have increased by exactly the fee (possibly
// from zero, in which case start balances wouldn't include its denomination).
const feeDenomIndex = vbankReserveStartBalances.findIndex(
({ denom }) => denom === feeDenom,
);
const preFeeAmount =
feeDenomIndex < 0
? 0n
: BigInt(vbankReserveStartBalances[feeDenomIndex].amount);
const beforeCount =
feeDenomIndex < 0 ? vbankReserveStartBalances.length : feeDenomIndex;
const vbankReserveExpectedBalances = [
...vbankReserveStartBalances.slice(0, beforeCount),
{ amount: String(preFeeAmount + feeAmount), denom: feeDenom },
...vbankReserveStartBalances.slice(beforeCount + 1),
];
t.deepEqual(
vbankReserveEndBalances,
vbankReserveExpectedBalances,
'vbank/reserve should receive the fee',
);
});