-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use referenda for testing transferable balance --------- Co-authored-by: Andrea Giacobino <[email protected]>
- Loading branch information
1 parent
9014c50
commit 2b9982e
Showing
9 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
test/suites/dev/test-balance/test-balance-transferable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import "@moonbeam-network/api-augment"; | ||
import { beforeAll, describeSuite, expect } from "@moonwall/cli"; | ||
import { ALITH_ADDRESS, GLMR, baltathar, checkBalance, generateKeyringPair } from "@moonwall/util"; | ||
import { createProposal } from "../../../helpers/voting.ts"; | ||
|
||
describeSuite({ | ||
id: "D4005", | ||
title: "Balance - Transferable", | ||
foundationMethods: "dev", | ||
testCases: ({ context, it }) => { | ||
const randomAccount = generateKeyringPair(); | ||
const randomAddress = randomAccount.address as `0x${string}`; | ||
|
||
beforeAll(async function () { | ||
await context.createBlock( | ||
context.polkadotJs().tx.balances.transfer(randomAccount.address, 38n * GLMR), | ||
{ allowFailures: false } | ||
); | ||
}); | ||
|
||
it({ | ||
id: "T01", | ||
title: "Consistent Transferable Balance Computation for Fee Calculation and Actual Balance", | ||
test: async function () { | ||
{ | ||
// In this test, the following actions are performed: | ||
// 1. A new account is created with an initial balance of 38 GLMR. | ||
// 2. An identity proposal is submitted by randomAccount (~15 GLMR) | ||
// 3. 20 GLMR are delegated to Alith from randomAccount. | ||
// 4. 5 GLMR are transferred to Balthazar from randomAccount. | ||
// 5. A second transfer of 2 GLMR to Balthazar is performed from randomAccount. | ||
|
||
// Delegate to Alith | ||
const { result: res } = await context.createBlock( | ||
context | ||
.polkadotJs() | ||
.tx.parachainStaking.delegate(ALITH_ADDRESS, 20n * GLMR, 10, 10) | ||
.signAsync(randomAccount) | ||
); | ||
expect(res!.successful).to.be.true; | ||
|
||
// Create a proposal | ||
const propNum = await createProposal({ context, from: randomAccount }); | ||
expect(propNum).toBe(0); | ||
|
||
// Balance after proposal | ||
const balanceAfter = ( | ||
await context.polkadotJs().query.system.account(randomAccount.address) | ||
).data.free.toBigInt(); | ||
|
||
// Check the balance of randomAccount before tranfer | ||
const balanceBeforeTransfer = await checkBalance(context, randomAddress); | ||
expect(balanceBeforeTransfer).toBeGreaterThan(9n * GLMR); | ||
|
||
// Get fee for transfer | ||
const fee = await context | ||
.polkadotJs() | ||
.tx.balances.transfer(randomAccount.address, 5n * GLMR) | ||
.paymentInfo(randomAccount.address); | ||
|
||
// Transfer 5 GLMR to Balthazar | ||
const { result: res3 } = await context.createBlock( | ||
context | ||
.polkadotJs() | ||
.tx.balances.transfer(baltathar.address, 5n * GLMR) | ||
.signAsync(randomAccount) | ||
); | ||
|
||
expect(res3!.successful).to.be.true; | ||
expect(await checkBalance(context, randomAddress)).toBe( | ||
balanceBeforeTransfer - 5n * GLMR - fee.partialFee.toBigInt() | ||
); | ||
expect(await checkBalance(context, randomAddress)).toBeGreaterThan(4n * GLMR); | ||
|
||
// Do a second transfer of 2 GLMR to Balthazar | ||
// const { result: res2 } = await context.createBlock( | ||
// context | ||
// .polkadotJs() | ||
// .tx.balances.transfer(baltathar.address, 2n * GLMR) | ||
// .signAsync(randomAccount) | ||
// ); | ||
// expect(res2!.successful).to.be.true; | ||
|
||
// TODO Change this check once the transferable balance is fixed | ||
// Check Ticket MOON-2598: https://opslayer.atlassian.net/browse/MOON-2598 | ||
expect( | ||
async () => | ||
await context.createBlock( | ||
context | ||
.polkadotJs() | ||
.tx.balances.transfer(baltathar.address, 2n * GLMR) | ||
.signAsync(randomAccount) | ||
) | ||
).rejects.toThrowError( | ||
"1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low" | ||
); | ||
} | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters