Skip to content

Commit 0bfd8a1

Browse files
authored
Merge pull request #423 from proto-kit/test/add-appchain-cleanup
Test/add appchain cleanup
2 parents 6c71ee2 + 368eba1 commit 0bfd8a1

File tree

13 files changed

+204
-130
lines changed

13 files changed

+204
-130
lines changed

packages/indexer/test/IndexerNotifier.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ describe.skip("IndexerNotifier", () => {
178178
await sendTransactions(appChain, 2);
179179
}, 20000);
180180

181+
afterAll(async () => {
182+
await appChain.close();
183+
});
184+
181185
it("should create a task for every unproven block produced", async () => {
182186
const { block } = container
183187
.resolve(IndexBlockTaskParametersSerializer)

packages/processor/test/HandlersExecutor.test.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,37 @@ const alice = alicePrivateKey.toPublicKey();
2121

2222
const bobPrivateKey = PrivateKey.random();
2323
const bob = bobPrivateKey.toPublicKey();
24+
function createAppChain() {
25+
const appChain = TestingAppChain.fromRuntime({
26+
Balances: Balances,
27+
});
2428

29+
appChain.configurePartial({
30+
Runtime: {
31+
Balances: {},
32+
},
33+
});
34+
return appChain;
35+
}
2536
describe("HandlersModule", () => {
26-
it("should handle blocks", async () => {
27-
const appChain = TestingAppChain.fromRuntime({
28-
Balances: Balances,
29-
});
37+
let appChain: ReturnType<typeof createAppChain>;
3038

31-
appChain.configurePartial({
32-
Runtime: {
33-
Balances: {},
34-
},
35-
});
39+
it("should handle blocks", async () => {
40+
appChain = createAppChain();
3641

3742
await appChain.start();
3843

3944
const trackBalanceOnBlockHandler: BlockHandler<PrismaClient> = async (
4045
client,
4146
{ block, result: blockResult }
4247
) => {
48+
const app = appChain;
4349
// iterate over all transactions
4450
for (const tx of block.transactions) {
4551
const methodId = tx.tx.methodId.toBigInt();
4652

4753
const methodDescriptor =
48-
appChain.runtime.methodIdResolver.getMethodNameFromId(methodId);
54+
app.runtime.methodIdResolver.getMethodNameFromId(methodId);
4955

5056
if (methodDescriptor === undefined) {
5157
throw new Error("Unable to retrieve the method descriptor");
@@ -56,7 +62,7 @@ describe("HandlersModule", () => {
5662

5763
const handleBalancesTransferSigned = async () => {
5864
console.log("handleBalancesTransferSigned");
59-
const module = appChain.runtime.resolve("Balances");
65+
const module = app.runtime.resolve("Balances");
6066

6167
const parameterDecoder = MethodParameterEncoder.fromMethod(
6268
module,
@@ -176,4 +182,8 @@ describe("HandlersModule", () => {
176182
expect(balance.address).toBe(alice.toBase58());
177183
expect(balance.amount).toBe("0");
178184
});
185+
186+
afterAll(async () => {
187+
await appChain.close();
188+
});
179189
});

packages/sdk/test/TestingAppChain.test.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,38 @@ class CustomBalances extends Balances<BalancesConfig> {
7979
public foo() {}
8080
}
8181

82+
function createAppChain(sender: PublicKey) {
83+
const appChain = TestingAppChain.fromRuntime({
84+
Admin,
85+
Balances: CustomBalances,
86+
});
87+
88+
appChain.configurePartial({
89+
Runtime: {
90+
Admin: {
91+
admin: sender,
92+
},
93+
94+
Balances: {
95+
totalSupply: UInt64.from(1000),
96+
},
97+
},
98+
Protocol: {
99+
...appChain.config.Protocol!,
100+
TransactionFee: {
101+
tokenId: 0n,
102+
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
103+
baseFee: 0n,
104+
perWeightUnitFee: 0n,
105+
methods: {},
106+
},
107+
},
108+
});
109+
return appChain;
110+
}
111+
82112
describe("testing app chain", () => {
113+
let appChain: ReturnType<typeof createAppChain>;
83114
it("should enable a complete transaction roundtrip", async () => {
84115
expect.assertions(2);
85116

@@ -90,33 +121,7 @@ describe("testing app chain", () => {
90121
* Setup the app chain for testing purposes,
91122
* using the provided runtime modules
92123
*/
93-
const appChain = TestingAppChain.fromRuntime({
94-
Admin,
95-
Balances: CustomBalances,
96-
});
97-
98-
appChain.configurePartial({
99-
Runtime: {
100-
Admin: {
101-
admin: sender,
102-
},
103-
104-
Balances: {
105-
totalSupply: UInt64.from(1000),
106-
},
107-
},
108-
Protocol: {
109-
...appChain.config.Protocol!,
110-
TransactionFee: {
111-
tokenId: 0n,
112-
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
113-
baseFee: 0n,
114-
perWeightUnitFee: 0n,
115-
methods: {},
116-
},
117-
},
118-
});
119-
124+
appChain = createAppChain(sender);
120125
// start the chain, sequencer is now accepting transactions
121126
await appChain.start();
122127

@@ -158,4 +163,8 @@ describe("testing app chain", () => {
158163

159164
expect(balance?.toBigInt()).toBe(1000n);
160165
}, 60_000);
166+
167+
afterAll(async () => {
168+
await appChain.close();
169+
});
161170
});

packages/sdk/test/XYK/XYK.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ describe("xyk", () => {
6868
xyk = chain.runtime.resolve("XYK");
6969
}, 60_000);
7070

71+
afterAll(async () => {
72+
await chain.close();
73+
});
74+
7175
it("should mint balance for alice", async () => {
7276
expect.assertions(2);
7377

packages/sdk/test/blockProof/blockProof.test.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,32 @@ import { TestingAppChain } from "../../src/testing/TestingAppChain";
2222

2323
import { TestBalances } from "./TestBalances";
2424

25+
function createAppChain(totalSupply: UInt64) {
26+
const appChain = TestingAppChain.fromRuntime({
27+
Balances: TestBalances,
28+
});
29+
30+
appChain.configurePartial({
31+
Runtime: {
32+
Balances: {
33+
totalSupply,
34+
},
35+
},
36+
});
37+
38+
return appChain;
39+
}
2540
// Failing - investigate why
2641
describe.skip("blockProof", () => {
42+
let appChain: ReturnType<typeof createAppChain>;
2743
it("should transition block state hash", async () => {
2844
expect.assertions(3);
2945

3046
const merklestore = new MockAsyncMerkleTreeStore();
3147
const tree = new RollupMerkleTree(merklestore.store);
3248

3349
const totalSupply = UInt64.from(10_000);
34-
35-
const appChain = TestingAppChain.fromRuntime({
36-
Balances: TestBalances,
37-
});
38-
39-
appChain.configurePartial({
40-
Runtime: {
41-
Balances: {
42-
totalSupply,
43-
},
44-
},
45-
});
50+
appChain = createAppChain(totalSupply);
4651

4752
await appChain.start();
4853

@@ -143,5 +148,7 @@ describe.skip("blockProof", () => {
143148

144149
expect(block?.transactions[0].status.toBoolean()).toBe(true);
145150
expect(aliceBalance?.toBigInt()).toBe(1000n);
151+
152+
await appChain.close();
146153
}, 120_000);
147154
});

packages/sdk/test/fee-hook-sts-regression.test.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,39 @@ class CustomBalances extends Balances<BalancesConfig> {
7878
// @runtimeMethod()
7979
public foo() {}
8080
}
81+
function createAppChain(sender: PublicKey) {
82+
const appChain = TestingAppChain.fromRuntime({
83+
Admin,
84+
Balances: CustomBalances,
85+
});
86+
87+
appChain.configurePartial({
88+
Runtime: {
89+
Admin: {
90+
admin: sender,
91+
},
92+
93+
Balances: {
94+
totalSupply: UInt64.from(10000),
95+
},
96+
},
97+
Protocol: {
98+
...appChain.config.Protocol!,
99+
TransactionFee: {
100+
tokenId: 0n,
101+
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
102+
baseFee: 0n,
103+
perWeightUnitFee: 0n,
104+
methods: {},
105+
},
106+
},
107+
});
108+
109+
return appChain;
110+
}
81111

82112
describe("testing app chain", () => {
113+
let appChain: ReturnType<typeof createAppChain>;
83114
it("should enable a complete transaction roundtrip", async () => {
84115
expect.assertions(4);
85116

@@ -90,33 +121,7 @@ describe("testing app chain", () => {
90121
* Setup the app chain for testing purposes,
91122
* using the provided runtime modules
92123
*/
93-
const appChain = TestingAppChain.fromRuntime({
94-
Admin,
95-
Balances: CustomBalances,
96-
});
97-
98-
appChain.configurePartial({
99-
Runtime: {
100-
Admin: {
101-
admin: sender,
102-
},
103-
104-
Balances: {
105-
totalSupply: UInt64.from(10000),
106-
},
107-
},
108-
Protocol: {
109-
...appChain.config.Protocol!,
110-
TransactionFee: {
111-
tokenId: 0n,
112-
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
113-
baseFee: 0n,
114-
perWeightUnitFee: 0n,
115-
methods: {},
116-
},
117-
},
118-
});
119-
124+
appChain = createAppChain(sender);
120125
// start the chain, sequencer is now accepting transactions
121126
await appChain.start();
122127

@@ -178,4 +183,8 @@ describe("testing app chain", () => {
178183

179184
expect(balance?.toBigInt()).toBe(2000n);
180185
}, 60_000);
186+
187+
afterAll(async () => {
188+
await appChain.close();
189+
});
181190
});

packages/sdk/test/fees.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ describe("fees", () => {
7979
appChain.setSigner(senderKey);
8080
}, 60_000);
8181

82+
afterAll(async () => {
83+
await appChain.close();
84+
});
85+
8286
it("should allow a free faucet transaction", async () => {
8387
expect.assertions(2);
8488

packages/sdk/test/minting-error.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ describe("balances", () => {
6161
appChain.setSigner(senderKey);
6262
}, 60_000);
6363

64+
afterAll(async () => {
65+
await appChain.close();
66+
});
67+
6468
it("regression - transfer from and to same account does not cause minting error", async () => {
6569
// expect.assertions(2);
6670
const faucet = appChain.runtime.resolve("Faucet");

0 commit comments

Comments
 (0)