diff --git a/package-lock.json b/package-lock.json index 083518689..fa18feec8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6914,7 +6914,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -6931,7 +6930,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -6948,7 +6946,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ @@ -6965,7 +6962,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -6982,7 +6978,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -6999,7 +6994,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -7016,7 +7010,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -7033,7 +7026,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -7050,7 +7042,6 @@ "cpu": [ "ia32" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -7067,7 +7058,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -7087,7 +7077,6 @@ "version": "0.5.18", "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.18.tgz", "integrity": "sha512-TXTnIcNJQEKwThMMqBXsZ4VGAza6bvN4pa41Rkqoio6QBKMvo+5lexeTMScGCIxtzgQJzElcvIltani+adC5PQ==", - "dev": true, "license": "Apache-2.0", "optional": true, "peer": true, diff --git a/packages/indexer/test/IndexerNotifier.test.ts b/packages/indexer/test/IndexerNotifier.test.ts index 31ab57210..ddd37b498 100644 --- a/packages/indexer/test/IndexerNotifier.test.ts +++ b/packages/indexer/test/IndexerNotifier.test.ts @@ -178,6 +178,10 @@ describe.skip("IndexerNotifier", () => { await sendTransactions(appChain, 2); }, 20000); + afterAll(async () => { + await appChain.close(); + }); + it("should create a task for every unproven block produced", async () => { const { block } = container .resolve(IndexBlockTaskParametersSerializer) diff --git a/packages/processor/test/HandlersExecutor.test.ts b/packages/processor/test/HandlersExecutor.test.ts index 49cf8ad15..71fa27e10 100644 --- a/packages/processor/test/HandlersExecutor.test.ts +++ b/packages/processor/test/HandlersExecutor.test.ts @@ -21,18 +21,23 @@ const alice = alicePrivateKey.toPublicKey(); const bobPrivateKey = PrivateKey.random(); const bob = bobPrivateKey.toPublicKey(); +function createAppChain() { + const appChain = TestingAppChain.fromRuntime({ + Balances: Balances, + }); + appChain.configurePartial({ + Runtime: { + Balances: {}, + }, + }); + return appChain; +} describe("HandlersModule", () => { - it("should handle blocks", async () => { - const appChain = TestingAppChain.fromRuntime({ - Balances: Balances, - }); + let appChain: ReturnType; - appChain.configurePartial({ - Runtime: { - Balances: {}, - }, - }); + it("should handle blocks", async () => { + appChain = createAppChain(); await appChain.start(); @@ -40,12 +45,13 @@ describe("HandlersModule", () => { client, { block, result: blockResult } ) => { + const app = appChain; // iterate over all transactions for (const tx of block.transactions) { const methodId = tx.tx.methodId.toBigInt(); const methodDescriptor = - appChain.runtime.methodIdResolver.getMethodNameFromId(methodId); + app.runtime.methodIdResolver.getMethodNameFromId(methodId); if (methodDescriptor === undefined) { throw new Error("Unable to retrieve the method descriptor"); @@ -56,7 +62,7 @@ describe("HandlersModule", () => { const handleBalancesTransferSigned = async () => { console.log("handleBalancesTransferSigned"); - const module = appChain.runtime.resolve("Balances"); + const module = app.runtime.resolve("Balances"); const parameterDecoder = MethodParameterEncoder.fromMethod( module, @@ -176,4 +182,8 @@ describe("HandlersModule", () => { expect(balance.address).toBe(alice.toBase58()); expect(balance.amount).toBe("0"); }); + + afterAll(async () => { + await appChain.close(); + }); }); diff --git a/packages/sdk/test/TestingAppChain.test.ts b/packages/sdk/test/TestingAppChain.test.ts index f07a6c21c..7f46624bc 100644 --- a/packages/sdk/test/TestingAppChain.test.ts +++ b/packages/sdk/test/TestingAppChain.test.ts @@ -79,7 +79,38 @@ class CustomBalances extends Balances { public foo() {} } +function createAppChain(sender: PublicKey) { + const appChain = TestingAppChain.fromRuntime({ + Admin, + Balances: CustomBalances, + }); + + appChain.configurePartial({ + Runtime: { + Admin: { + admin: sender, + }, + + Balances: { + totalSupply: UInt64.from(1000), + }, + }, + Protocol: { + ...appChain.config.Protocol!, + TransactionFee: { + tokenId: 0n, + feeRecipient: PrivateKey.random().toPublicKey().toBase58(), + baseFee: 0n, + perWeightUnitFee: 0n, + methods: {}, + }, + }, + }); + return appChain; +} + describe("testing app chain", () => { + let appChain: ReturnType; it("should enable a complete transaction roundtrip", async () => { expect.assertions(2); @@ -90,33 +121,7 @@ describe("testing app chain", () => { * Setup the app chain for testing purposes, * using the provided runtime modules */ - const appChain = TestingAppChain.fromRuntime({ - Admin, - Balances: CustomBalances, - }); - - appChain.configurePartial({ - Runtime: { - Admin: { - admin: sender, - }, - - Balances: { - totalSupply: UInt64.from(1000), - }, - }, - Protocol: { - ...appChain.config.Protocol!, - TransactionFee: { - tokenId: 0n, - feeRecipient: PrivateKey.random().toPublicKey().toBase58(), - baseFee: 0n, - perWeightUnitFee: 0n, - methods: {}, - }, - }, - }); - + appChain = createAppChain(sender); // start the chain, sequencer is now accepting transactions await appChain.start(); @@ -158,4 +163,8 @@ describe("testing app chain", () => { expect(balance?.toBigInt()).toBe(1000n); }, 60_000); + + afterAll(async () => { + await appChain.close(); + }); }); diff --git a/packages/sdk/test/XYK/XYK.test.ts b/packages/sdk/test/XYK/XYK.test.ts index fdbc4cfc7..7ab804b83 100644 --- a/packages/sdk/test/XYK/XYK.test.ts +++ b/packages/sdk/test/XYK/XYK.test.ts @@ -68,6 +68,10 @@ describe("xyk", () => { xyk = chain.runtime.resolve("XYK"); }, 60_000); + afterAll(async () => { + await chain.close(); + }); + it("should mint balance for alice", async () => { expect.assertions(2); diff --git a/packages/sdk/test/blockProof/blockProof.test.ts b/packages/sdk/test/blockProof/blockProof.test.ts index 1ac9e0376..97e748bc1 100644 --- a/packages/sdk/test/blockProof/blockProof.test.ts +++ b/packages/sdk/test/blockProof/blockProof.test.ts @@ -22,8 +22,24 @@ import { TestingAppChain } from "../../src/testing/TestingAppChain"; import { TestBalances } from "./TestBalances"; +function createAppChain(totalSupply: UInt64) { + const appChain = TestingAppChain.fromRuntime({ + Balances: TestBalances, + }); + + appChain.configurePartial({ + Runtime: { + Balances: { + totalSupply, + }, + }, + }); + + return appChain; +} // Failing - investigate why describe.skip("blockProof", () => { + let appChain: ReturnType; it("should transition block state hash", async () => { expect.assertions(3); @@ -31,18 +47,7 @@ describe.skip("blockProof", () => { const tree = new RollupMerkleTree(merklestore.store); const totalSupply = UInt64.from(10_000); - - const appChain = TestingAppChain.fromRuntime({ - Balances: TestBalances, - }); - - appChain.configurePartial({ - Runtime: { - Balances: { - totalSupply, - }, - }, - }); + appChain = createAppChain(totalSupply); await appChain.start(); @@ -143,5 +148,7 @@ describe.skip("blockProof", () => { expect(block?.transactions[0].status.toBoolean()).toBe(true); expect(aliceBalance?.toBigInt()).toBe(1000n); + + await appChain.close(); }, 120_000); }); diff --git a/packages/sdk/test/fee-hook-sts-regression.test.ts b/packages/sdk/test/fee-hook-sts-regression.test.ts index 69a47d39d..ac0e8b6cc 100644 --- a/packages/sdk/test/fee-hook-sts-regression.test.ts +++ b/packages/sdk/test/fee-hook-sts-regression.test.ts @@ -78,8 +78,39 @@ class CustomBalances extends Balances { // @runtimeMethod() public foo() {} } +function createAppChain(sender: PublicKey) { + const appChain = TestingAppChain.fromRuntime({ + Admin, + Balances: CustomBalances, + }); + + appChain.configurePartial({ + Runtime: { + Admin: { + admin: sender, + }, + + Balances: { + totalSupply: UInt64.from(10000), + }, + }, + Protocol: { + ...appChain.config.Protocol!, + TransactionFee: { + tokenId: 0n, + feeRecipient: PrivateKey.random().toPublicKey().toBase58(), + baseFee: 0n, + perWeightUnitFee: 0n, + methods: {}, + }, + }, + }); + + return appChain; +} describe("testing app chain", () => { + let appChain: ReturnType; it("should enable a complete transaction roundtrip", async () => { expect.assertions(4); @@ -90,33 +121,7 @@ describe("testing app chain", () => { * Setup the app chain for testing purposes, * using the provided runtime modules */ - const appChain = TestingAppChain.fromRuntime({ - Admin, - Balances: CustomBalances, - }); - - appChain.configurePartial({ - Runtime: { - Admin: { - admin: sender, - }, - - Balances: { - totalSupply: UInt64.from(10000), - }, - }, - Protocol: { - ...appChain.config.Protocol!, - TransactionFee: { - tokenId: 0n, - feeRecipient: PrivateKey.random().toPublicKey().toBase58(), - baseFee: 0n, - perWeightUnitFee: 0n, - methods: {}, - }, - }, - }); - + appChain = createAppChain(sender); // start the chain, sequencer is now accepting transactions await appChain.start(); @@ -178,4 +183,8 @@ describe("testing app chain", () => { expect(balance?.toBigInt()).toBe(2000n); }, 60_000); + + afterAll(async () => { + await appChain.close(); + }); }); diff --git a/packages/sdk/test/fees.test.ts b/packages/sdk/test/fees.test.ts index 9adaa126d..8e829d3fc 100644 --- a/packages/sdk/test/fees.test.ts +++ b/packages/sdk/test/fees.test.ts @@ -79,6 +79,10 @@ describe("fees", () => { appChain.setSigner(senderKey); }, 60_000); + afterAll(async () => { + await appChain.close(); + }); + it("should allow a free faucet transaction", async () => { expect.assertions(2); diff --git a/packages/sdk/test/minting-error.test.ts b/packages/sdk/test/minting-error.test.ts index 37f7d8740..422ca543f 100644 --- a/packages/sdk/test/minting-error.test.ts +++ b/packages/sdk/test/minting-error.test.ts @@ -61,6 +61,10 @@ describe("balances", () => { appChain.setSigner(senderKey); }, 60_000); + afterAll(async () => { + await appChain.close(); + }); + it("regression - transfer from and to same account does not cause minting error", async () => { // expect.assertions(2); const faucet = appChain.runtime.resolve("Faucet"); diff --git a/packages/sdk/test/modularization.test.ts b/packages/sdk/test/modularization.test.ts index f0ee7a8bb..cf47084ce 100644 --- a/packages/sdk/test/modularization.test.ts +++ b/packages/sdk/test/modularization.test.ts @@ -43,44 +43,52 @@ class TestSequencerModule extends SequencerModule { } } +function createAppChain() { + const appChain = AppChain.from({ + Runtime: Runtime.from( + VanillaRuntimeModules.with({ + TestRuntimeModule, + }) + ), + Protocol: Protocol.from( + VanillaProtocolModules.with({ + TestProtocolModule, + }) + ), + Sequencer: Sequencer.from({ + TestSequencerModule, + }), + }); + + appChain.configurePartial({ + Runtime: { + Balances: {}, + TestRuntimeModule: {}, + }, + Protocol: { + ...Protocol.defaultConfig(), + TransactionFee: { + tokenId: 0n, + feeRecipient: PrivateKey.random().toPublicKey().toBase58(), + baseFee: 0n, + perWeightUnitFee: 0n, + methods: {}, + }, + TestProtocolModule: {}, + }, + Sequencer: { + TestSequencerModule: {}, + }, + }); + + return appChain; +} + describe("modularization", () => { + let appChain: ReturnType; + it("should initialize all modules correctly", async () => { - const appChain = AppChain.from({ - Runtime: Runtime.from( - VanillaRuntimeModules.with({ - TestRuntimeModule, - }) - ), - Protocol: Protocol.from( - VanillaProtocolModules.with({ - TestProtocolModule, - }) - ), - Sequencer: Sequencer.from({ - TestSequencerModule, - }), - }); - - appChain.configurePartial({ - Runtime: { - Balances: {}, - TestRuntimeModule: {}, - }, - Protocol: { - ...Protocol.defaultConfig(), - TransactionFee: { - tokenId: 0n, - feeRecipient: PrivateKey.random().toPublicKey().toBase58(), - baseFee: 0n, - perWeightUnitFee: 0n, - methods: {}, - }, - TestProtocolModule: {}, - }, - Sequencer: { - TestSequencerModule: {}, - }, - }); + appChain = createAppChain(); await appChain.start(); @@ -109,4 +117,8 @@ describe("modularization", () => { appChain.runtime.resolveOrFail("MethodIdResolver", MethodIdResolver) ).toBeDefined(); }); + + afterAll(async () => { + await appChain.close(); + }); }); diff --git a/packages/sdk/test/networkstate/NetworkState.test.ts b/packages/sdk/test/networkstate/NetworkState.test.ts index f2b812a6e..1127f5020 100644 --- a/packages/sdk/test/networkstate/NetworkState.test.ts +++ b/packages/sdk/test/networkstate/NetworkState.test.ts @@ -73,6 +73,10 @@ describe.skip("block production", () => { blockTrigger = sequencer.resolve("BlockTrigger"); }); + afterEach(async () => { + await appchain.close(); + }); + it("stateproof test", async () => { log.setLevel("INFO"); diff --git a/packages/sdk/test/parameters.test.ts b/packages/sdk/test/parameters.test.ts index 9212d8420..e4b053bc6 100644 --- a/packages/sdk/test/parameters.test.ts +++ b/packages/sdk/test/parameters.test.ts @@ -94,7 +94,21 @@ class TestRuntime extends RuntimeModule { } } +function createAppChain() { + const appChain = TestingAppChain.fromRuntime({ + TestRuntime, + }); + + appChain.configurePartial({ + Runtime: { + TestRuntime: {}, + Balances: {}, + }, + }); + return appChain; +} describe("parameters", () => { + let appChain: ReturnType; it("should accept various provable transaction arguments", async () => { expect.assertions(2); @@ -105,19 +119,8 @@ describe("parameters", () => { * Setup the app chain for testing purposes, * using the provided runtime modules */ - const appChain = TestingAppChain.fromRuntime({ - TestRuntime, - }); - - appChain.configurePartial({ - Runtime: { - TestRuntime: {}, - Balances: {}, - }, - }); - + appChain = createAppChain(); await appChain.start(); - appChain.setSigner(signer); const runtime = appChain.runtime.resolve("TestRuntime"); @@ -148,4 +151,8 @@ describe("parameters", () => { expectDefined(block); expect(block.transactions[0].status.toBoolean()).toBe(true); }, 60_000); + + afterAll(async () => { + await appChain.close(); + }); }); diff --git a/packages/sequencer/test-proven/Proven.test.ts b/packages/sequencer/test-proven/Proven.test.ts index 43b41df19..14e41f9dd 100644 --- a/packages/sequencer/test-proven/Proven.test.ts +++ b/packages/sequencer/test-proven/Proven.test.ts @@ -78,10 +78,6 @@ describe("Proven", () => { }); } - afterAll(async () => { - await appChain.close(); - }); - it( "should start up and compile", async () => { @@ -225,7 +221,6 @@ describe("Proven", () => { }, timeout ); - it( "should produce large block", async () => { @@ -264,4 +259,8 @@ describe("Proven", () => { }, timeout * 10 ); + + afterAll(async () => { + await appChain.close(); + }); }); diff --git a/packages/stack/test/graphql/graphql.test.ts b/packages/stack/test/graphql/graphql.test.ts index 45b29206b..f174f97f0 100644 --- a/packages/stack/test/graphql/graphql.test.ts +++ b/packages/stack/test/graphql/graphql.test.ts @@ -112,6 +112,7 @@ describe("graphql client test", () => { }, 20_000); afterAll(async () => { + await appChain.close(); await server.sequencer.close(); }, 20_000);