-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
CctpTxEvidenceShape
, PendingTxShape
typeGuards
- Loading branch information
1 parent
5e4139c
commit 5a7b3d2
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { M } from '@endo/patterns'; | ||
import { PendingTxStatus } from './constants.js'; | ||
|
||
/** | ||
* @import {TypedPattern} from '@agoric/internal'; | ||
* @import {CctpTxEvidence, PendingTx} from './types.js'; | ||
*/ | ||
|
||
/** @type {TypedPattern<string>} */ | ||
export const EvmHashShape = M.string({ | ||
stringLengthLimit: 66, | ||
}); | ||
harden(EvmHashShape); | ||
|
||
/** @type {TypedPattern<CctpTxEvidence>} */ | ||
export const CctpTxEvidenceShape = { | ||
aux: { | ||
forwardingChannel: M.string(), | ||
recipientAddress: M.string(), | ||
}, | ||
blockHash: EvmHashShape, | ||
blockNumber: M.bigint(), | ||
blockTimestamp: M.bigint(), | ||
chainId: M.number(), | ||
tx: { | ||
amount: M.bigint(), | ||
forwardingAddress: M.string(), | ||
}, | ||
txHash: EvmHashShape, | ||
}; | ||
harden(CctpTxEvidenceShape); | ||
|
||
/** @type {TypedPattern<PendingTx>} */ | ||
// @ts-expect-error TypedPattern can't handle spreading? | ||
export const PendingTxShape = { | ||
...CctpTxEvidenceShape, | ||
status: M.or(...Object.values(PendingTxStatus)), | ||
}; | ||
harden(PendingTxShape); |
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,39 @@ | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import { mustMatch } from '@endo/patterns'; | ||
import { TxStatus, PendingTxStatus } from '../src/constants.js'; | ||
import { CctpTxEvidenceShape, PendingTxShape } from '../src/typeGuards.js'; | ||
import type { CctpTxEvidence } from '../src/types.js'; | ||
|
||
import { MockCctpTxEvidences } from './fixtures.js'; | ||
|
||
test('CctpTxEvidenceShape', t => { | ||
const specimen: CctpTxEvidence = harden( | ||
MockCctpTxEvidences.AGORIC_PLUS_OSMO(), | ||
); | ||
|
||
t.notThrows(() => mustMatch(specimen, CctpTxEvidenceShape)); | ||
}); | ||
|
||
test('PendingTxShape', t => { | ||
const specimen: CctpTxEvidence & { status: TxStatus } = harden({ | ||
...MockCctpTxEvidences.AGORIC_PLUS_OSMO(), | ||
status: PendingTxStatus.Observed, | ||
}); | ||
|
||
t.notThrows(() => mustMatch(specimen, PendingTxShape)); | ||
|
||
t.notThrows(() => | ||
mustMatch( | ||
harden({ ...specimen, status: PendingTxStatus.Advanced }), | ||
PendingTxShape, | ||
), | ||
); | ||
|
||
t.throws(() => | ||
mustMatch( | ||
harden({ ...specimen, status: TxStatus.Settled }), | ||
PendingTxShape, | ||
), | ||
); | ||
}); |