forked from Joystream/hydra
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hydra-indexer): add default values in case SubstrateExtrinsic pro…
…perties are undefined (e.g. tip affects: @subsquid/hydra-indexer ISSUES CLOSED: #70
- Loading branch information
Showing
2 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/hydra-indexer/src/entities/SubstrateExtrinsicEntity.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { expect } from 'chai' | ||
import { Extrinsic } from '@polkadot/types/interfaces' | ||
import { SubstrateBlockEntity } from './SubstrateBlockEntity' | ||
import { fromBlockExtrinsic } from './SubstrateExtrinsicEntity' | ||
|
||
const testData: { | ||
e: Extrinsic | ||
blockEntity: SubstrateBlockEntity | ||
indexInBlock: number | ||
} = { | ||
e: { | ||
isSigned: true, | ||
hash: { toString: () => '0xdcdca' } as any, | ||
signature: { toString: () => '0xbbbbb' } as any, | ||
signer: { toString: () => '0xaaaaa' } as any, | ||
nonce: { toNumber: () => 12332 } as any, | ||
method: { | ||
method: 'method', | ||
section: 'section', | ||
args: [], | ||
} as any, | ||
} as any, | ||
blockEntity: { | ||
height: 6666, | ||
hash: '0xaaaaaa', | ||
} as any, | ||
indexInBlock: 1, | ||
} | ||
|
||
describe('SubstrateExtrinsicEntity', () => { | ||
it('handles non-standard tips', () => { | ||
const fromTestData = fromBlockExtrinsic(testData) | ||
|
||
expect(fromTestData.tip).eq(BigInt(0), 'should set tip to zero by default') | ||
}) | ||
|
||
it('creates block extrinsics', () => { | ||
const fromTestData = fromBlockExtrinsic(testData) | ||
|
||
expect(fromTestData.hash).eq('0xdcdca', 'should set hash') | ||
expect(fromTestData.signature).eq('0xbbbbb', 'should set signature') | ||
expect(fromTestData.signer).eq('0xaaaaa', 'should set signer') | ||
expect(fromTestData.meta).eql({}, 'should set default meta') | ||
expect(fromTestData.nonce).eq(12332, 'should set nonce') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters