Skip to content

Commit 4781dc8

Browse files
authored
chore: replace all uses of tx.balances.transfer() (#903)
* chore: replace all uses of tx.balances.transfer() * test: update mocks
1 parent b657abb commit 4781dc8

8 files changed

Lines changed: 43 additions & 28 deletions

File tree

packages/chain-helpers/src/blockchain/Blockchain.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ describe('Blockchain', () => {
3434

3535
it('allows waiting for finalization', async () => {
3636
api.__setDefaultResult({ isFinalized: true })
37-
const tx = api.tx.balances.transfer('abcdef', 50)
37+
const tx = api.tx.balances.transferAllowDeath('abcdef', 50)
3838
expect(
3939
await signAndSubmitTx(tx, pair, { resolveOn: IS_FINALIZED })
4040
).toHaveProperty('isFinalized', true)
4141
})
4242

4343
it('allows waiting for in block', async () => {
4444
api.__setDefaultResult({ isInBlock: true })
45-
const tx = api.tx.balances.transfer('abcdef', 50)
45+
const tx = api.tx.balances.transferAllowDeath('abcdef', 50)
4646
expect(
4747
await signAndSubmitTx(tx, pair, { resolveOn: IS_IN_BLOCK })
4848
).toHaveProperty('isInBlock', true)
4949
})
5050

5151
it('allows waiting for ready', async () => {
5252
api.__setDefaultResult({ isReady: true })
53-
const tx = api.tx.balances.transfer('abcdef', 50)
53+
const tx = api.tx.balances.transferAllowDeath('abcdef', 50)
5454
expect(
5555
await signAndSubmitTx(tx, pair, { resolveOn: IS_READY })
5656
).toHaveProperty('status.isReady', true)
@@ -59,20 +59,20 @@ describe('Blockchain', () => {
5959
it('uses default resolution config', async () => {
6060
api.__setDefaultResult({ isReady: true })
6161
ConfigService.set({ submitTxResolveOn: IS_READY })
62-
let tx = api.tx.balances.transfer('abcdef', 50)
62+
let tx = api.tx.balances.transferAllowDeath('abcdef', 50)
6363
expect(await signAndSubmitTx(tx, pair)).toHaveProperty(
6464
'status.isReady',
6565
true
6666
)
6767

6868
api.__setDefaultResult({ isInBlock: true })
6969
ConfigService.set({ submitTxResolveOn: IS_IN_BLOCK })
70-
tx = api.tx.balances.transfer('abcdef', 50)
70+
tx = api.tx.balances.transferAllowDeath('abcdef', 50)
7171
expect(await signAndSubmitTx(tx, pair)).toHaveProperty('isInBlock', true)
7272

7373
api.__setDefaultResult({ isFinalized: true })
7474
ConfigService.set({ submitTxResolveOn: IS_FINALIZED })
75-
tx = api.tx.balances.transfer('abcdef', 50)
75+
tx = api.tx.balances.transferAllowDeath('abcdef', 50)
7676
expect(await signAndSubmitTx(tx, pair)).toHaveProperty(
7777
'isFinalized',
7878
true
@@ -81,7 +81,7 @@ describe('Blockchain', () => {
8181

8282
it('rejects on error condition', async () => {
8383
api.__setDefaultResult({ isInvalid: true })
84-
const tx = api.tx.balances.transfer('abcdef', 50)
84+
const tx = api.tx.balances.transferAllowDeath('abcdef', 50)
8585
await expect(
8686
signAndSubmitTx(tx, pair, { resolveOn: IS_FINALIZED })
8787
).rejects.toHaveProperty('isError', true)
@@ -90,7 +90,7 @@ describe('Blockchain', () => {
9090
it('throws if subscriptions not supported', async () => {
9191
// @ts-ignore
9292
api.hasSubscriptions = false
93-
const tx = api.tx.balances.transfer('abcdef', 50)
93+
const tx = api.tx.balances.transferAllowDeath('abcdef', 50)
9494
await expect(
9595
signAndSubmitTx(tx, pair, { resolveOn: IS_FINALIZED })
9696
).rejects.toThrow(SDKErrors.SubscriptionsNotSupportedError)
@@ -102,7 +102,7 @@ describe('Blockchain', () => {
102102
// mock disconnect 500 ms after submission
103103
if (ev === 'disconnected') setTimeout(callback, 500)
104104
})
105-
const tx = api.tx.balances.transfer('abcdef', 50)
105+
const tx = api.tx.balances.transferAllowDeath('abcdef', 50)
106106
await expect(
107107
signAndSubmitTx(tx, pair, { resolveOn: IS_FINALIZED })
108108
).rejects.toHaveProperty('internalError', expect.any(Error))

tests/integration/Balance.spec.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ describe('when there is a dev chain with a faucet', () => {
6868
const spy = jest.fn<any>()
6969
api.query.system.account(address, spy)
7070
const balanceBefore = (await api.query.system.account(faucet.address)).data
71-
const transferTx = api.tx.balances.transfer(address, EXISTENTIAL_DEPOSIT)
71+
const transferTx = api.tx.balances.transferAllowDeath(
72+
address,
73+
EXISTENTIAL_DEPOSIT
74+
)
7275
await submitTx(transferTx, faucet)
7376
const balanceAfter = (await api.query.system.account(faucet.address)).data
7477
const balanceIdent = (await api.query.system.account(address)).data
@@ -95,7 +98,7 @@ describe('When there are haves and have-nots', () => {
9598
})
9699

97100
it('can transfer tokens from the rich to the poor', async () => {
98-
const transferTx = api.tx.balances.transfer(
101+
const transferTx = api.tx.balances.transferAllowDeath(
99102
stormyD.address,
100103
EXISTENTIAL_DEPOSIT
101104
)
@@ -107,7 +110,7 @@ describe('When there are haves and have-nots', () => {
107110
it('should not accept transactions from KeyringPair with zero balance', async () => {
108111
const originalBalance = (await api.query.system.account(stormyD.address))
109112
.data
110-
const transferTx = api.tx.balances.transfer(
113+
const transferTx = api.tx.balances.transferAllowDeath(
111114
stormyD.address,
112115
EXISTENTIAL_DEPOSIT
113116
)
@@ -125,7 +128,7 @@ describe('When there are haves and have-nots', () => {
125128
it.skip('should not accept transactions when sender cannot pay gas, but will keep gas fee', async () => {
126129
const RichieBalance = (await api.query.system.account(richieRich.address))
127130
.data
128-
const transferTx = api.tx.balances.transfer(
131+
const transferTx = api.tx.balances.transferAllowDeath(
129132
bobbyBroke.address,
130133
RichieBalance.free
131134
)
@@ -142,12 +145,12 @@ describe('When there are haves and have-nots', () => {
142145
const spy = jest.fn<any>()
143146
api.query.system.account(faucet.address, spy)
144147

145-
const transferTx1 = api.tx.balances.transfer(
148+
const transferTx1 = api.tx.balances.transferAllowDeath(
146149
richieRich.address,
147150
EXISTENTIAL_DEPOSIT
148151
)
149152
await submitTx(transferTx1, faucet)
150-
const transferTx2 = api.tx.balances.transfer(
153+
const transferTx2 = api.tx.balances.transferAllowDeath(
151154
stormyD.address,
152155
EXISTENTIAL_DEPOSIT
153156
)
@@ -161,8 +164,11 @@ describe('When there are haves and have-nots', () => {
161164
api.query.system.account(faucet.address, listener)
162165

163166
const batch = api.tx.utility.batchAll([
164-
api.tx.balances.transfer(richieRich.address, EXISTENTIAL_DEPOSIT),
165-
api.tx.balances.transfer(stormyD.address, EXISTENTIAL_DEPOSIT),
167+
api.tx.balances.transferAllowDeath(
168+
richieRich.address,
169+
EXISTENTIAL_DEPOSIT
170+
),
171+
api.tx.balances.transferAllowDeath(stormyD.address, EXISTENTIAL_DEPOSIT),
166172
])
167173
await submitTx(batch, faucet)
168174

tests/integration/Blockchain.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ describe('Chain returns specific errors, that we check for', () => {
3232
testIdentity = (await makeSigningKeyTool()).keypair
3333
charlie = devCharlie
3434

35-
const transferTx = api.tx.balances.transfer(
35+
const transferTx = api.tx.balances.transferAllowDeath(
3636
testIdentity.address,
3737
BalanceUtils.toFemtoKilt(10000)
3838
)
3939
await submitTx(transferTx, faucet)
4040
}, 40000)
4141

4242
it(`throws TxOutdated error if the nonce was already used for Tx in block`, async () => {
43-
const tx = api.tx.balances.transfer(
43+
const tx = api.tx.balances.transferAllowDeath(
4444
charlie.address,
4545
new BN('1000000000000001')
4646
)
47-
const errorTx = api.tx.balances.transfer(
47+
const errorTx = api.tx.balances.transferAllowDeath(
4848
charlie.address,
4949
new BN('1000000000000000')
5050
)
@@ -93,11 +93,11 @@ describe('Chain returns specific errors, that we check for', () => {
9393
}, 40000)
9494

9595
it(`throws 'ERROR_TRANSACTION_USURPED' error if separate Tx was imported with identical nonce but higher priority while Tx is in pool`, async () => {
96-
const tx = api.tx.balances.transfer(
96+
const tx = api.tx.balances.transferAllowDeath(
9797
charlie.address,
9898
new BN('1000000000000000')
9999
)
100-
const errorTx = api.tx.balances.transfer(
100+
const errorTx = api.tx.balances.transferAllowDeath(
101101
charlie.address,
102102
new BN('1000000000000000')
103103
)

tests/integration/Ctypes.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ describe('When there is an CtypeCreator and a verifier', () => {
105105
).data.free.toBigInt() < minBalance
106106
) {
107107
console.log('sending funds to assertion method key account...')
108-
const fundsTx = api.tx.balances.transfer(assertionMethodKey, minBalance)
108+
const fundsTx = api.tx.balances.transferAllowDeath(
109+
assertionMethodKey,
110+
minBalance
111+
)
109112
await submitTx(fundsTx, paymentAccount)
110113
console.log('sending funds completed')
111114
}

tests/integration/ErrorHandler.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ beforeAll(async () => {
4444
}, 60_000)
4545

4646
it('records an extrinsic error when transferring less than the existential amount to new identity', async () => {
47-
const transferTx = api.tx.balances.transfer(addressFromRandom(), 1)
47+
const transferTx = api.tx.balances.transferAllowDeath(addressFromRandom(), 1)
4848
const promise = submitTx(transferTx, paymentAccount)
4949
if (api.runtimeVersion.specVersion.toBigInt() >= 11_200n) {
5050
await expect(promise).rejects.toMatchInlineSnapshot(`

tests/integration/PublicCredentials.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ describe('When there is an attester and ctype NFT name', () => {
284284
).data.free.toBigInt() < minBalance
285285
) {
286286
console.log('sending funds to assertion method key account...')
287-
const fundsTx = api.tx.balances.transfer(assertionMethodKey, minBalance)
287+
const fundsTx = api.tx.balances.transferAllowDeath(
288+
assertionMethodKey,
289+
minBalance
290+
)
288291
await submitTx(fundsTx, tokenHolder)
289292
console.log('sending funds completed')
290293
}

tests/integration/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ export async function endowAccounts(
171171
): Promise<void> {
172172
const api = ConfigService.get('api')
173173
const transactions = await Promise.all(
174-
addresses.map((address) => api.tx.balances.transfer(address, ENDOWMENT))
174+
addresses.map((address) =>
175+
api.tx.balances.transferKeepAlive(address, ENDOWMENT)
176+
)
175177
)
176178
const batch = api.tx.utility.batchAll(transactions)
177179
await Blockchain.signAndSubmitTx(batch, faucet, { resolveOn })
@@ -182,7 +184,7 @@ export async function fundAccount(
182184
amount: BN
183185
): Promise<void> {
184186
const api = ConfigService.get('api')
185-
const transferTx = api.tx.balances.transfer(address, amount)
187+
const transferTx = api.tx.balances.transferKeepAlive(address, amount)
186188
await submitTx(transferTx, devFaucet)
187189
}
188190

tests/testUtils/mocks/mockedApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ export function getMockedApi(): MockApiPromise {
239239
reclaimDeposit: jest.fn((claimHash: string) => getMockSubmittableTx()),
240240
},
241241
balances: {
242-
transfer: jest.fn(() => getMockSubmittableTx()),
242+
transferAllowDeath: jest.fn(() => getMockSubmittableTx()),
243+
transferKeepAlive: jest.fn(() => getMockSubmittableTx()),
243244
},
244245
ctype: {
245246
add: jest.fn((hash, signature) => getMockSubmittableTx()),

0 commit comments

Comments
 (0)