11import { sendTransaction } from '@acala-network/chopsticks-testing'
22
3- import { type Chain , defaultAccountsSr25519 } from '@e2e-test/networks'
3+ import { type Chain , testAccounts } from '@e2e-test/networks'
44import { type Client , type RootTestTree , setupNetworks } from '@e2e-test/shared'
55
66import type { KeyringPair } from '@polkadot/keyring/types'
@@ -10,11 +10,11 @@ import { assert, expect } from 'vitest'
1010
1111import { match } from 'ts-pattern'
1212import {
13- type LowEdChain as ChainEd ,
1413 checkEvents ,
1514 checkSystemEvents ,
1615 createXcmTransactSend ,
1716 scheduleInlineCallWithOrigin ,
17+ type TestConfig ,
1818} from './helpers/index.js'
1919
2020/// -------
@@ -29,7 +29,7 @@ async function createAccountWithBalance<
2929 TInitStorages extends Record < string , Record < string , any > > | undefined ,
3030> ( client : Client < TCustom , TInitStorages > , balance : any , seed : string ) : Promise < KeyringPair > {
3131 // Create fresh account from seed
32- const newAccount = defaultAccountsSr25519 . keyring . createFromUri ( `${ seed } ` )
32+ const newAccount = testAccounts . keyring . createFromUri ( `${ seed } ` )
3333
3434 // Set account balance directly via storage
3535 await client . dev . setStorage ( {
@@ -84,7 +84,7 @@ async function transferAllowDeathTest<
8484 // When transferring this amount, net of fees, the account should have less than 1 ED remaining.
8585 const totalBalance = existentialDeposit + eps
8686 const alice = await createAccountWithBalance ( client , totalBalance , '//fresh_alice' )
87- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
87+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
8888
8989 // Verify both accounts have empty data before transfer
9090 expect ( await isAccountReaped ( client , alice . address ) ) . toBe ( false )
@@ -155,6 +155,8 @@ async function transferAllowDeathTest<
155155 return true
156156 }
157157 }
158+
159+ return false
158160 } )
159161 expect ( transferEvent ) . toBeDefined ( )
160162 assert ( client . api . events . balances . Transfer . is ( transferEvent ! . event ) )
@@ -242,7 +244,7 @@ async function transferAllowDeathNoKillTest<
242244 const existentialDeposit = client . api . consts . balances . existentialDeposit . toBigInt ( )
243245 const totalBalance = existentialDeposit * 100n // 100 ED
244246 const alice = await createAccountWithBalance ( client , totalBalance , '//fresh_alice' )
245- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
247+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
246248
247249 // Verify initial state
248250 expect ( await isAccountReaped ( client , alice . address ) ) . toBe ( false )
@@ -296,7 +298,7 @@ async function transferAllowDeathNoKillTest<
296298 } )
297299 expect ( killedAccountEvent ) . toBeUndefined ( )
298300
299- // Verify transfer event
301+ // Verify transfer event -- fee transfers also count, so a filter for the proper sender is needed.
300302 const transferEvent = events . find ( ( record ) => {
301303 const { event } = record
302304 if ( event . section === 'balances' && event . method === 'Transfer' ) {
@@ -305,6 +307,8 @@ async function transferAllowDeathNoKillTest<
305307 return true
306308 }
307309 }
310+
311+ return false
308312 } )
309313 expect ( transferEvent ) . toBeDefined ( )
310314 assert ( client . api . events . balances . Transfer . is ( transferEvent ! . event ) )
@@ -364,7 +368,7 @@ async function forceTransferKillTest<
364368 TInitStoragesRelay extends Record < string , Record < string , any > > | undefined ,
365369> (
366370 baseChain : Chain < TCustom , TInitStoragesBase > ,
367- addressEncoding : number ,
371+ testConfig : TestConfig ,
368372 relayChain ?: Chain < TCustom , TInitStoragesRelay > ,
369373) {
370374 let relayClient : Client < TCustom , TInitStoragesRelay >
@@ -391,7 +395,7 @@ async function forceTransferKillTest<
391395 const eps = existentialDeposit / 3n
392396 const totalBalance = existentialDeposit + eps
393397 const alice = await createAccountWithBalance ( baseClient , totalBalance , '//fresh_alice' )
394- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
398+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
395399
396400 // Verify both accounts have expected initial state
397401 expect ( await isAccountReaped ( baseClient , alice . address ) ) . toBe ( false )
@@ -401,7 +405,12 @@ async function forceTransferKillTest<
401405
402406 if ( hasScheduler ) {
403407 // Use root origin to execute force transfer directly
404- await scheduleInlineCallWithOrigin ( baseClient , forceTransferTx . method . toHex ( ) , { system : 'Root' } )
408+ await scheduleInlineCallWithOrigin (
409+ baseClient ,
410+ forceTransferTx . method . toHex ( ) ,
411+ { system : 'Root' } ,
412+ testConfig . blockProvider ,
413+ )
405414 await baseClient . dev . newBlock ( )
406415 } else {
407416 // Query parachain ID
@@ -421,7 +430,7 @@ async function forceTransferKillTest<
421430 'Superuser' ,
422431 )
423432
424- await scheduleInlineCallWithOrigin ( relayClient ! , xcmTx . method . toHex ( ) , { system : 'Root' } )
433+ await scheduleInlineCallWithOrigin ( relayClient ! , xcmTx . method . toHex ( ) , { system : 'Root' } , testConfig . blockProvider )
425434
426435 // Advance blocks on both chains
427436 await relayClient ! . dev . newBlock ( )
@@ -453,21 +462,23 @@ async function forceTransferKillTest<
453462 // 5. `NewAccount` event
454463 const events = await baseClient . api . query . system . events ( )
455464
456- // Check `Transfer` event
465+ // Check `Transfer` event - again, filter to disambiguate fee transfers
457466 const transferEvent = events . find ( ( record ) => {
458467 const { event } = record
459468 if ( event . section === 'balances' && event . method === 'Transfer' ) {
460469 assert ( baseClient . api . events . balances . Transfer . is ( event ) )
461- if ( event . data . from . toString ( ) === encodeAddress ( alice . address , addressEncoding ) ) {
470+ if ( event . data . from . toString ( ) === encodeAddress ( alice . address , testConfig . addressEncoding ) ) {
462471 return true
463472 }
464473 }
474+
475+ return false
465476 } )
466477 expect ( transferEvent ) . toBeDefined ( )
467478 assert ( baseClient . api . events . balances . Transfer . is ( transferEvent ! . event ) )
468479 const transferEventData = transferEvent ! . event . data
469- expect ( transferEventData . from . toString ( ) ) . toBe ( encodeAddress ( alice . address , addressEncoding ) )
470- expect ( transferEventData . to . toString ( ) ) . toBe ( encodeAddress ( bob . address , addressEncoding ) )
480+ expect ( transferEventData . from . toString ( ) ) . toBe ( encodeAddress ( alice . address , testConfig . addressEncoding ) )
481+ expect ( transferEventData . to . toString ( ) ) . toBe ( encodeAddress ( bob . address , testConfig . addressEncoding ) )
471482 expect ( transferEventData . amount . toBigInt ( ) ) . toBe ( existentialDeposit )
472483
473484 // Check `DustLost` event
@@ -478,7 +489,7 @@ async function forceTransferKillTest<
478489 expect ( dustLostEvent ) . toBeDefined ( )
479490 assert ( baseClient . api . events . balances . DustLost . is ( dustLostEvent ! . event ) )
480491 const dustLostEventData = dustLostEvent ! . event . data
481- expect ( dustLostEventData . account . toString ( ) ) . toBe ( encodeAddress ( alice . address , addressEncoding ) )
492+ expect ( dustLostEventData . account . toString ( ) ) . toBe ( encodeAddress ( alice . address , testConfig . addressEncoding ) )
482493 expect ( dustLostEventData . amount . toBigInt ( ) ) . toBe ( eps )
483494
484495 // Check `Endowed` event
@@ -489,7 +500,7 @@ async function forceTransferKillTest<
489500 expect ( endowedEvent ) . toBeDefined ( )
490501 assert ( baseClient . api . events . balances . Endowed . is ( endowedEvent ! . event ) )
491502 const endowedEventData = endowedEvent ! . event . data
492- expect ( endowedEventData . account . toString ( ) ) . toBe ( encodeAddress ( bob . address , addressEncoding ) )
503+ expect ( endowedEventData . account . toString ( ) ) . toBe ( encodeAddress ( bob . address , testConfig . addressEncoding ) )
493504 expect ( endowedEventData . freeBalance . toBigInt ( ) ) . toBe ( existentialDeposit )
494505
495506 // Check `KilledAccount` event
@@ -500,7 +511,7 @@ async function forceTransferKillTest<
500511 expect ( killedAccountEvent ) . toBeDefined ( )
501512 assert ( baseClient . api . events . system . KilledAccount . is ( killedAccountEvent ! . event ) )
502513 const killedAccountEventData = killedAccountEvent ! . event . data
503- expect ( killedAccountEventData . account . toString ( ) ) . toBe ( encodeAddress ( alice . address , addressEncoding ) )
514+ expect ( killedAccountEventData . account . toString ( ) ) . toBe ( encodeAddress ( alice . address , testConfig . addressEncoding ) )
504515
505516 // Check `NewAccount` event
506517 const newAccountEvent = events . find ( ( record ) => {
@@ -510,7 +521,7 @@ async function forceTransferKillTest<
510521 expect ( newAccountEvent ) . toBeDefined ( )
511522 assert ( baseClient . api . events . system . NewAccount . is ( newAccountEvent ! . event ) )
512523 const newAccountEventData = newAccountEvent ! . event . data
513- expect ( newAccountEventData . account . toString ( ) ) . toBe ( encodeAddress ( bob . address , addressEncoding ) )
524+ expect ( newAccountEventData . account . toString ( ) ) . toBe ( encodeAddress ( bob . address , testConfig . addressEncoding ) )
514525}
515526
516527/**
@@ -531,7 +542,7 @@ async function transferBelowExistentialDepositTest<
531542 const existentialDeposit = client . api . consts . balances . existentialDeposit . toBigInt ( )
532543 const aliceBalance = existentialDeposit * 100n // 100 ED
533544 const alice = await createAccountWithBalance ( client , aliceBalance , '//fresh_alice' )
534- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
545+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
535546
536547 // Verify initial state
537548 expect ( await isAccountReaped ( client , alice . address ) ) . toBe ( false )
@@ -595,7 +606,7 @@ async function transferInsufficientFundsTest<
595606 const existentialDeposit = client . api . consts . balances . existentialDeposit . toBigInt ( )
596607 const totalBalance = existentialDeposit * 100n
597608 const alice = await createAccountWithBalance ( client , totalBalance , '//fresh_alice' )
598- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
609+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
599610
600611 expect ( await isAccountReaped ( client , alice . address ) ) . toBe ( false )
601612 expect ( await isAccountReaped ( client , bob . address ) ) . toBe ( true )
@@ -719,7 +730,7 @@ async function forceTransferBelowExistentialDepositTest<
719730 TInitStoragesRelay extends Record < string , Record < string , any > > | undefined ,
720731> (
721732 baseChain : Chain < TCustom , TInitStoragesBase > ,
722- _addressEncoding : number ,
733+ testConfig : TestConfig ,
723734 relayChain ?: Chain < TCustom , TInitStoragesRelay > ,
724735) {
725736 let relayClient : Client < TCustom , TInitStoragesRelay >
@@ -744,7 +755,7 @@ async function forceTransferBelowExistentialDepositTest<
744755 const existentialDeposit = baseClient . api . consts . balances . existentialDeposit . toBigInt ( )
745756 const aliceBalance = existentialDeposit * 100n // 100 ED
746757 const alice = await createAccountWithBalance ( baseClient , aliceBalance , '//fresh_alice' )
747- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
758+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
748759
749760 // Verify initial state
750761 expect ( await isAccountReaped ( baseClient , alice . address ) ) . toBe ( false )
@@ -755,7 +766,12 @@ async function forceTransferBelowExistentialDepositTest<
755766
756767 if ( hasScheduler ) {
757768 // Use root origin to execute force transfer directly
758- await scheduleInlineCallWithOrigin ( baseClient , forceTransferTx . method . toHex ( ) , { system : 'Root' } )
769+ await scheduleInlineCallWithOrigin (
770+ baseClient ,
771+ forceTransferTx . method . toHex ( ) ,
772+ { system : 'Root' } ,
773+ testConfig . blockProvider ,
774+ )
759775 await baseClient . dev . newBlock ( )
760776 } else {
761777 // Query parachain ID
@@ -775,7 +791,7 @@ async function forceTransferBelowExistentialDepositTest<
775791 'Superuser' ,
776792 )
777793
778- await scheduleInlineCallWithOrigin ( relayClient ! , xcmTx . method . toHex ( ) , { system : 'Root' } )
794+ await scheduleInlineCallWithOrigin ( relayClient ! , xcmTx . method . toHex ( ) , { system : 'Root' } , testConfig . blockProvider )
779795
780796 // Advance blocks on both chains
781797 await relayClient ! . dev . newBlock ( )
@@ -830,7 +846,7 @@ async function forceTransferInsufficientFundsTest<
830846 TInitStoragesRelay extends Record < string , Record < string , any > > | undefined ,
831847> (
832848 baseChain : Chain < TCustom , TInitStoragesBase > ,
833- _addressEncoding : number ,
849+ testConfig : TestConfig ,
834850 relayChain ?: Chain < TCustom , TInitStoragesRelay > ,
835851) {
836852 let relayClient : Client < TCustom , TInitStoragesRelay >
@@ -855,7 +871,7 @@ async function forceTransferInsufficientFundsTest<
855871 const existentialDeposit = baseClient . api . consts . balances . existentialDeposit . toBigInt ( )
856872 const aliceBalance = existentialDeposit
857873 const alice = await createAccountWithBalance ( baseClient , aliceBalance , '//fresh_alice' )
858- const bob = defaultAccountsSr25519 . keyring . createFromUri ( '//fresh_bob' )
874+ const bob = testAccounts . keyring . createFromUri ( '//fresh_bob' )
859875
860876 expect ( await isAccountReaped ( baseClient , alice . address ) ) . toBe ( false )
861877 expect ( await isAccountReaped ( baseClient , bob . address ) ) . toBe ( true )
@@ -865,7 +881,12 @@ async function forceTransferInsufficientFundsTest<
865881 const forceTransferTx = baseClient . api . tx . balances . forceTransfer ( alice . address , bob . address , transferAmount )
866882
867883 if ( hasScheduler ) {
868- await scheduleInlineCallWithOrigin ( baseClient , forceTransferTx . method . toHex ( ) , { system : 'Root' } )
884+ await scheduleInlineCallWithOrigin (
885+ baseClient ,
886+ forceTransferTx . method . toHex ( ) ,
887+ { system : 'Root' } ,
888+ testConfig . blockProvider ,
889+ )
869890 await baseClient . dev . newBlock ( )
870891 } else {
871892 // Query parachain ID
@@ -885,7 +906,7 @@ async function forceTransferInsufficientFundsTest<
885906 'Superuser' ,
886907 )
887908
888- await scheduleInlineCallWithOrigin ( relayClient ! , xcmTx . method . toHex ( ) , { system : 'Root' } )
909+ await scheduleInlineCallWithOrigin ( relayClient ! , xcmTx . method . toHex ( ) , { system : 'Root' } , testConfig . blockProvider )
889910
890911 // Advance blocks on both chains
891912 await relayClient ! . dev . newBlock ( )
@@ -929,8 +950,8 @@ async function forceTransferBadOriginTest(chain: Chain) {
929950 // Create fresh accounts
930951 const existentialDeposit = client . api . consts . balances . existentialDeposit . toBigInt ( )
931952 const transferAmount = existentialDeposit
932- const alice = defaultAccountsSr25519 . alice
933- const bob = defaultAccountsSr25519 . bob
953+ const alice = testAccounts . alice
954+ const bob = testAccounts . bob
934955
935956 const forceTransferTx = client . api . tx . balances . forceTransfer ( alice . address , bob . address , transferAmount )
936957 await sendTransaction ( forceTransferTx . signAsync ( alice ) ) // Regular user, not root
@@ -1013,11 +1034,7 @@ const partialTransferAllowDeathTests = (
10131034 children : commonTransferAllowDeathTests ( chain , testConfig ) ,
10141035} )
10151036
1016- export const transferFunctionsTests = (
1017- chain : Chain ,
1018- testConfig : { testSuiteName : string ; addressEncoding : number ; chainEd : ChainEd } ,
1019- relayChain ?: Chain ,
1020- ) : RootTestTree => ( {
1037+ export const transferFunctionsTests = ( chain : Chain , testConfig : TestConfig , relayChain ?: Chain ) : RootTestTree => ( {
10211038 kind : 'describe' ,
10221039 label : testConfig . testSuiteName ,
10231040 children : [
@@ -1042,17 +1059,17 @@ export const transferFunctionsTests = (
10421059 {
10431060 kind : 'test' as const ,
10441061 label : 'force transfer below ED can kill source account' ,
1045- testFn : ( ) => forceTransferKillTest ( chain , testConfig . addressEncoding , relayChain ) ,
1062+ testFn : ( ) => forceTransferKillTest ( chain , testConfig , relayChain ) ,
10461063 } ,
10471064 {
10481065 kind : 'test' as const ,
10491066 label : 'force transfer below existential deposit fails' ,
1050- testFn : ( ) => forceTransferBelowExistentialDepositTest ( chain , testConfig . addressEncoding , relayChain ) ,
1067+ testFn : ( ) => forceTransferBelowExistentialDepositTest ( chain , testConfig , relayChain ) ,
10511068 } ,
10521069 {
10531070 kind : 'test' as const ,
10541071 label : 'force transfer with insufficient funds fails' ,
1055- testFn : ( ) => forceTransferInsufficientFundsTest ( chain , testConfig . addressEncoding , relayChain ) ,
1072+ testFn : ( ) => forceTransferInsufficientFundsTest ( chain , testConfig , relayChain ) ,
10561073 } ,
10571074 {
10581075 kind : 'test' ,
0 commit comments