1515// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
1717import { ApiPromise } from '@polkadot/api' ;
18- import { BlockHash } from '@polkadot/types/interfaces' ;
1918import BN from 'bn.js' ;
2019
2120import { polkadotRegistry } from '../../test-helpers/registries' ;
@@ -24,7 +23,7 @@ import { getRelayParentNumber, hasRelayParentData } from './getRelayParentNumber
2423const mockBlockHash = polkadotRegistry . createType (
2524 'BlockHash' ,
2625 '0x7b713de604a99857f6c25eacc115a4f28d2611a23d9ddff99ab0e4f1c17a8578' ,
27- ) as BlockHash ;
26+ ) ;
2827
2928const mockRelayParentNumber = 28500000 ;
3029
@@ -76,19 +75,22 @@ describe('getRelayParentNumber', () => {
7675 } ,
7776 } ;
7877
78+ const mockAt = jest . fn ( ) . mockResolvedValue ( mockApiAt ) ;
79+ const mockGetBlock = jest . fn ( ) . mockResolvedValue ( {
80+ block : {
81+ extrinsics : [
82+ createMockOtherExtrinsic ( 'timestamp' ) ,
83+ createMockSetValidationDataExtrinsic ( ) ,
84+ createMockOtherExtrinsic ( 'transfer' ) ,
85+ ] ,
86+ } ,
87+ } ) ;
88+
7989 const mockApi = {
80- at : jest . fn ( ) . mockResolvedValue ( mockApiAt ) ,
90+ at : mockAt ,
8191 rpc : {
8292 chain : {
83- getBlock : jest . fn ( ) . mockResolvedValue ( {
84- block : {
85- extrinsics : [
86- createMockOtherExtrinsic ( 'timestamp' ) ,
87- createMockSetValidationDataExtrinsic ( ) ,
88- createMockOtherExtrinsic ( 'transfer' ) ,
89- ] ,
90- } ,
91- } ) ,
93+ getBlock : mockGetBlock ,
9294 } ,
9395 } ,
9496 } as unknown as ApiPromise ;
@@ -97,8 +99,8 @@ describe('getRelayParentNumber', () => {
9799
98100 expect ( result ) . toBeInstanceOf ( BN ) ;
99101 expect ( result . toNumber ( ) ) . toBe ( mockRelayParentNumber ) ;
100- expect ( mockApi . at ) . toHaveBeenCalledWith ( mockBlockHash ) ;
101- expect ( mockApi . rpc . chain . getBlock ) . toHaveBeenCalledWith ( mockBlockHash ) ;
102+ expect ( mockAt ) . toHaveBeenCalledWith ( mockBlockHash ) ;
103+ expect ( mockGetBlock ) . toHaveBeenCalledWith ( mockBlockHash ) ;
102104 } ) ;
103105
104106 it ( 'should throw error when setValidationData extrinsic is not found' , async ( ) => {
@@ -108,10 +110,7 @@ describe('getRelayParentNumber', () => {
108110 chain : {
109111 getBlock : jest . fn ( ) . mockResolvedValue ( {
110112 block : {
111- extrinsics : [
112- createMockOtherExtrinsic ( 'timestamp' ) ,
113- createMockOtherExtrinsic ( 'transfer' ) ,
114- ] ,
113+ extrinsics : [ createMockOtherExtrinsic ( 'timestamp' ) , createMockOtherExtrinsic ( 'transfer' ) ] ,
115114 } ,
116115 } ) ,
117116 } ,
@@ -182,10 +181,7 @@ describe('getRelayParentNumber', () => {
182181 chain : {
183182 getBlock : jest . fn ( ) . mockResolvedValue ( {
184183 block : {
185- extrinsics : [
186- createMockOtherExtrinsic ( 'timestamp' ) ,
187- createMockSetValidationDataExtrinsic ( ) ,
188- ] ,
184+ extrinsics : [ createMockOtherExtrinsic ( 'timestamp' ) , createMockSetValidationDataExtrinsic ( ) ] ,
189185 } ,
190186 } ) ,
191187 } ,
@@ -203,10 +199,7 @@ describe('getRelayParentNumber', () => {
203199 chain : {
204200 getBlock : jest . fn ( ) . mockResolvedValue ( {
205201 block : {
206- extrinsics : [
207- createMockOtherExtrinsic ( 'timestamp' ) ,
208- createMockOtherExtrinsic ( 'transfer' ) ,
209- ] ,
202+ extrinsics : [ createMockOtherExtrinsic ( 'timestamp' ) , createMockOtherExtrinsic ( 'transfer' ) ] ,
210203 } ,
211204 } ) ,
212205 } ,
0 commit comments