Skip to content

Commit 33071f2

Browse files
authored
Add P-chain test scripts
1 parent 9f8debf commit 33071f2

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

test-scripts/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
Tests are performed on **localflare** network and include:
44
- C-chain to P-chain transfer (100 FLR)
55
- P-chain to C-chain transfer (100 FLR)
6-
- Add validator (`NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ` with weight 10.000 FLR and duration of 14 days)
7-
- Add delegator (To node `NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg` with weight 10.000 FLR and duration of 1 hour)
6+
- Add validator (`NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ` with weight 10,000 FLR and duration of 14 days)
7+
- Add delegator (To node `NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg` with weight 10,000 FLR and duration of 1 hour)
88

9-
Run localflare with in `avalanchego` directory:
9+
Run localflare in `avalanchego` directory:
1010
```bash
1111
./scripts/build.sh. # Build avalanchego
1212
./scripts/localflare.sh. # Run 5 localflare nodes
1313
```
1414
Check that the nodes are running by visiting `http://localhost:9650/ext/health` in your browser.
1515

16-
Then, in a separate terminal, run the test scripts in this directory:
16+
Then, in a separate terminal, run the test scripts in this (`test-scripts`) directory:
1717
```bash
18-
yarn
18+
yarn
1919
yarn run p-chain-import
2020
yarn run p-chain-export
2121
yarn run add-validator
2222
yarn run add-delegator
2323
```
2424
Note:
25-
- Nodejs version 20 in requred to run the scripts, also make sure you have the `yarn` package manager installed.
25+
- Nodejs version 20 is required to run the scripts, also make sure you have the `yarn` package manager installed.
2626
- The scripts assume that the localflare network is running and accessible at the default ports.

test-scripts/src/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CChainBalance, formatDecimal, PChainBalance } from "./utils";
22

3-
async function runWithBalanches(func: () => Promise<void>) {
3+
async function runWithBalances(func: () => Promise<void>) {
44
// Log the current balances before calling the function
55
let cBalanceFLR = await CChainBalance();
66
let pBalanceFLR = await PChainBalance();
@@ -20,7 +20,7 @@ async function runWithBalanches(func: () => Promise<void>) {
2020

2121
export async function runTest(func: () => Promise<void>) {
2222
try {
23-
await runWithBalanches(func);
23+
await runWithBalances(func);
2424
console.log('Script completed successfully');
2525
} catch (error) {
2626
console.error('Script failed:', error);

test-scripts/src/test-add-delegator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { runTest } from "./runner";
55
async function addDelegator(nodeID: string, endTime: number, weight: number) {
66
const ctx = await localFlareContext();
77

8-
// Create the transaction to add a delegator
8+
// Create the transaction to add a delegator
99
console.log(`Creating add delegator transaction for node ${nodeID} with weight ${weight}...`);
1010

1111
const { utxos } = await ctx.pvmapi.getUTXOs({
@@ -19,7 +19,7 @@ async function addDelegator(nodeID: string, endTime: number, weight: number) {
1919
networkIDs.PrimaryNetworkID.toString(),
2020
BigInt(Date.now()) / 1000n,
2121
BigInt(endTime),
22-
BigInt(weight * 1e9),
22+
BigInt(weight * 1e9),
2323
[utils.bech32ToBytes(ctx.addressP)],
2424
);
2525

@@ -28,6 +28,6 @@ async function addDelegator(nodeID: string, endTime: number, weight: number) {
2828

2929
runTest(() => addDelegator(
3030
'NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg',
31-
Math.ceil(Date.now() / 1000) + 60 * 60 + 5, // 1 hour (+ 5 seconds) from now
31+
Math.ceil(Date.now() / 1000) + 60 * 60 + 5, // 1 hour (+ 5 seconds) from now
3232
10_000
3333
))

test-scripts/src/test-add-validator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { networkIDs, pvm, utils } from "@flarenetwork/flarejs";
22
import { issuePChainTx, localFlareContext } from "./utils";
33
import { runTest } from "./runner";
44

5-
const blsPublicKey = '0x917386c374aab0ea3d2bda96768f2be1f0b11483cd5c41bd9cddd3892b693ab84efecc6cf70300d614dcdc6d298ab659';
5+
const blsPublicKey = '0x917386c374aab0ea3d2bda96768f2be1f0b11483cd5c41bd9cddd3892b693ab84efecc6cf70300d614dcdc6d298ab659';
66
const blsSignature = '0x81c7174fc3bc9bbf00a1e26cc7b177d92589b517df5c46844498c14ede655bfedb89929e3d2974210983a1ff06a2a39b05208974a2d3dddac4948bcc81f367717d960be9704b775f21022d639b439135d34b7fb1f2bacbb5ffab3ddafc86220f'
77

88
async function addValidator(nodeID: string, endTime: number, weight: number) {
@@ -22,7 +22,7 @@ async function addValidator(nodeID: string, endTime: number, weight: number) {
2222
networkIDs.PrimaryNetworkID.toString(),
2323
BigInt(Date.now()) / 1000n,
2424
BigInt(endTime),
25-
BigInt(weight * 1e9),
25+
BigInt(weight * 1e9),
2626
[utils.bech32ToBytes(ctx.addressP)],
2727
[utils.bech32ToBytes(ctx.addressP)],
2828
10_0000,
@@ -38,6 +38,6 @@ async function addValidator(nodeID: string, endTime: number, weight: number) {
3838

3939
runTest(() => addValidator(
4040
'NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ',
41-
Math.ceil(Date.now() / 1000) + 14 * 24 * 60 * 60 + 5, // 14 days (+ 5 seconds) from now
41+
Math.ceil(Date.now() / 1000) + 14 * 24 * 60 * 60 + 5, // 14 days (+ 5 seconds) from now
4242
10_000
4343
))

test-scripts/src/test-p-chain-export.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { runTest } from './runner';
44

55
async function PtoCExport(amountFLR: number) {
66
const ctx = await localFlareContext();
7-
const baseFee = await ctx.evmapi.getBaseFee();
7+
const fee = 1; // in FLR
88

99
// Create and issue a P to C export transaction
1010
console.log(`Creating P to C export transaction for ${amountFLR} FLR...`);
@@ -33,13 +33,13 @@ async function PtoCExport(amountFLR: number) {
3333
addresses: ['C-' + ctx.addressP.slice(2)],
3434
});
3535

36-
const importTx = evm.newImportTxFromBaseFee(
36+
const importTx = evm.newImportTx(
3737
ctx.context,
3838
utils.hexToBuffer(ctx.addressC),
3939
[utils.bech32ToBytes(ctx.addressP)],
4040
utxosc,
4141
ctx.context.pBlockchainID,
42-
baseFee / BigInt(1e9),
42+
BigInt(fee * 1e9),
4343
);
4444

4545
await issueCChainTx(ctx.evmapi, importTx, ctx.privateKey);

test-scripts/src/test-p-chain-import.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import { runTest } from './runner';
44

55
async function CtoPExport(amountFLR: number) {
66
const ctx = await localFlareContext();
7-
const baseFee = await ctx.evmapi.getBaseFee();
7+
const fee = 1; // in FLR
88
const txCount = await ctx.provider.getTransactionCount(ctx.addressC);
99

1010
// Create and issue a C to P export transaction
1111
console.log(`Creating C to P export transaction for ${amountFLR} FLR...`);
1212

13-
const exportTx = evm.newExportTxFromBaseFee(
13+
const exportTx = evm.newExportTx(
1414
ctx.context,
15-
baseFee / BigInt(1e9),
1615
BigInt(amountFLR * 1e9),
1716
ctx.context.pBlockchainID,
1817
utils.hexToBuffer(ctx.addressC),
1918
[utils.bech32ToBytes(ctx.addressP)],
19+
BigInt(fee * 1e9),
2020
BigInt(txCount),
21-
);
21+
)
2222

2323
await issueCChainTx(ctx.evmapi, exportTx, ctx.privateKey);
2424

test-scripts/src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { evm, pvm, Context, addTxSignatures, UnsignedTx, utils} from '@flarenetwork/flarejs';
1+
import { evm, pvm, Context, addTxSignatures, UnsignedTx, utils } from '@flarenetwork/flarejs';
22
import { JsonRpcProvider } from 'ethers'
33

44
export const LocalURL = 'http://localhost:9650';
@@ -68,7 +68,7 @@ export async function issuePChainTx(pvmapi: pvm.PVMApi, tx: UnsignedTx, privateK
6868

6969
const exportResponse = await pvmapi.issueSignedTx(tx.getSignedTx());
7070
const txID = exportResponse.txID;
71-
console.log(`Issued transaction with ID: ${txID}`);
71+
console.log(`Issued transaction with ID: ${txID}`);
7272

7373
console.log(`Waiting for transaction ${txID} to be processed...`);
7474
let txStatus;
@@ -88,11 +88,11 @@ export async function issueCChainTx(evmapi: evm.EVMApi, tx: UnsignedTx, privateK
8888
await addTxSignatures({
8989
unsignedTx: tx,
9090
privateKeys: [utils.hexToBuffer(privateKey)],
91-
});
91+
});
9292

9393
const exportResponse = await evmapi.issueSignedTx(tx.getSignedTx());
9494
const txID = exportResponse.txID;
95-
console.log(`Issued transaction with ID: ${txID}`);
95+
console.log(`Issued transaction with ID: ${txID}`);
9696

9797
console.log(`Waiting for transaction ${txID} to be processed...`);
9898
let txStatus;

0 commit comments

Comments
 (0)