Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
HYP-13: onchain tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3op2 committed Nov 17, 2023
1 parent b5eed68 commit dfd3706
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0",
"@types/sinon": "^17.0.1",
"@types/supertest": "^2.0.16",
"@types/swagger-ui-express": "^4.1.6",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.10.0",
Expand Down
12 changes: 6 additions & 6 deletions src/lib/chainNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class ChainNode {

async submitRunProcess(
extrinsic: SubmittableExtrinsic<'promise', SubmittableResult>,
transactionDbUpdate: (state: TransactionState) => Promise<void>
update: (state: TransactionState) => Promise<Record<string, string>[]>
): Promise<void> {
try {
this.logger.debug('Submitting Transaction %j', extrinsic.hash.toHex())
Expand All @@ -184,7 +184,7 @@ export default class ChainNode {

if (dispatchError) {
this.logger.warn('dispatch error %s', dispatchError)
transactionDbUpdate('failed')
update('failed')
unsub()
if (dispatchError.isModule) {
const decoded = this.api.registry.findMetaError(dispatchError.asModule)
Expand All @@ -194,23 +194,23 @@ export default class ChainNode {
throw new Error(`Unknown node dispatch error: ${dispatchError}`)
}

if (status.isInBlock) transactionDbUpdate('inBlock')
if (status.isInBlock) update('inBlock')
if (status.isFinalized) {
const processRanEvent = result.events.find(({ event: { method } }) => method === 'ProcessRan')
const data = processRanEvent?.event?.data as EventData
const tokens = data?.outputs?.map((x) => x.toNumber())

if (!tokens) {
transactionDbUpdate('failed')
update('failed')
throw new Error('No token IDs returned')
}

transactionDbUpdate('finalised')
update('finalised')
unsub()
}
})
} catch (err) {
transactionDbUpdate('failed')
update('failed')
this.logger.warn(`Error in run process transaction: ${err}`)
}
}
Expand Down

0 comments on commit dfd3706

Please sign in to comment.