@@ -21,31 +21,37 @@ const alice = alicePrivateKey.toPublicKey();
2121
2222const bobPrivateKey = PrivateKey . random ( ) ;
2323const 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+ }
2536describe ( "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} ) ;
0 commit comments