Skip to content

Commit

Permalink
feat: consistent publishTxnRecord (record)
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 16, 2024
1 parent 7da240f commit 33173f9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ Generated by [AVA](https://avajs.dev).
[
[
'published.fastUsdc.txns.0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761702',
'ADVANCING',
'{"body":"#{\\"status\\":\\"ADVANCING\\"}","slots":[]}',
],
]
Binary file modified packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.snap
Binary file not shown.
23 changes: 16 additions & 7 deletions packages/fast-usdc/src/exos/status-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PendingTxStatus, TerminalTxStatus, TxStatus } from '../constants.js';
* @import {MapStore, SetStore} from '@agoric/store';
* @import {Zone} from '@agoric/zone';
* @import {CctpTxEvidence, NobleAddress, PendingTx, EvmHash, LogFn} from '../types.js';
* @import {CopyRecord} from '@endo/pass-style';
*/

/**
Expand Down Expand Up @@ -98,27 +99,35 @@ export const prepareStatusManager = (
keyShape: M.string(),
});

/**
* @param {EvmHash} txId
* @param {CopyRecord} record
*/
const publishTxnRecord = (txId, record) => {
const txNode = E(transactionsNode).makeChildNode(txId, {
sequence: true, // avoid overwriting other output in the block
});
void E(txNode).setValue(
JSON.stringify(pureDataMarshaller.toCapData(harden(record))),
);
};

/**
* @param {CctpTxEvidence['txHash']} hash
* @param {CctpTxEvidence} evidence
*/
const publishEvidence = (hash, evidence) => {
const txNode = E(transactionsNode).makeChildNode(hash);
// Don't await, just writing to vstorage.
void E(txNode).setValue(
// @ts-expect-error XXX CopyRecordI expects an index signature
JSON.stringify(pureDataMarshaller.toCapData(evidence)),
);
void publishTxnRecord(hash, evidence);
};

/**
* @param {CctpTxEvidence['txHash']} hash
* @param {TxStatus} status
*/
const publishStatus = (hash, status) => {
const txnNodeP = E(transactionsNode).makeChildNode(hash);
// Don't await, just writing to vstorage.
void E(txnNodeP).setValue(status);
void publishTxnRecord(hash, { status });
if (TerminalTxStatus[status]) {
// UNTIL https://github.com/Agoric/agoric-sdk/issues/7405
// Queue it for deletion later because if we deleted it now the earlier
Expand Down
21 changes: 10 additions & 11 deletions packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { type ZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js';
import { q } from '@endo/errors';
import { Far } from '@endo/pass-style';
import type { TestFn } from 'ava';
import { stringifyWithBigint } from '@agoric/internal';
import { PendingTxStatus } from '../../src/constants.js';
import { prepareAdvancer } from '../../src/exos/advancer.js';
import type { SettlerKit } from '../../src/exos/settler.js';
Expand Down Expand Up @@ -187,8 +186,8 @@ test('updates status to ADVANCING in happy path', async t => {
await eventLoopIteration();

t.deepEqual(
storage.getValues(`fun.txns.${mockEvidence.txHash}`),
[stringifyWithBigint(mockEvidence), PendingTxStatus.Advancing],
storage.getPureData(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Advancing }],
'ADVANCED status in happy path',
);

Expand Down Expand Up @@ -261,8 +260,8 @@ test('updates status to OBSERVED on insufficient pool funds', async t => {
await eventLoopIteration();

t.deepEqual(
storage.getValues(`fun.txns.${mockEvidence.txHash}`),
[stringifyWithBigint(mockEvidence), PendingTxStatus.Observed],
storage.getPureData(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Observed }],
'OBSERVED status on insufficient pool funds',
);

Expand Down Expand Up @@ -290,8 +289,8 @@ test('updates status to OBSERVED if makeChainAddress fails', async t => {
await advancer.handleTransactionEvent(mockEvidence);

t.deepEqual(
storage.getValues(`fun.txns.${mockEvidence.txHash}`),
[stringifyWithBigint(mockEvidence), PendingTxStatus.Observed],
storage.getPureData(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Observed }],
'OBSERVED status on makeChainAddress failure',
);

Expand Down Expand Up @@ -323,8 +322,8 @@ test('calls notifyAdvancingResult (AdvancedFailed) on failed transfer', async t
await eventLoopIteration();

t.deepEqual(
storage.getValues(`fun.txns.${mockEvidence.txHash}`),
[stringifyWithBigint(mockEvidence), PendingTxStatus.Advancing],
storage.getPureData(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Advancing }],
'tx is Advancing',
);

Expand Down Expand Up @@ -370,8 +369,8 @@ test('updates status to OBSERVED if pre-condition checks fail', async t => {
await advancer.handleTransactionEvent(mockEvidence);

t.deepEqual(
storage.getValues(`fun.txns.${mockEvidence.txHash}`),
[stringifyWithBigint(mockEvidence), PendingTxStatus.Observed],
storage.getPureData(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Observed }],
'tx is recorded as OBSERVED',
);

Expand Down
19 changes: 9 additions & 10 deletions packages/fast-usdc/test/exos/settler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { TestFn } from 'ava';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import fetchedChainInfo from '@agoric/orchestration/src/fetched-chain-info.js';
import type { Zone } from '@agoric/zone';
import { stringifyWithBigint } from '@agoric/internal';
import { PendingTxStatus } from '../../src/constants.js';
import { prepareSettler } from '../../src/exos/settler.js';
import { prepareStatusManager } from '../../src/exos/status-manager.js';
Expand Down Expand Up @@ -236,11 +235,11 @@ test('happy path: disburse to LPs; StatusManager removes tx', async t => {
);
await eventLoopIteration();
const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${cctpTxEvidence.txHash}`), [
stringifyWithBigint(cctpTxEvidence),
'ADVANCING',
'ADVANCED',
'DISBURSED',
t.deepEqual(storage.getPureData(`fun.txns.${cctpTxEvidence.txHash}`), [
cctpTxEvidence,
{ status: 'ADVANCING' },
{ status: 'ADVANCED' },
{ status: 'DISBURSED' },
]);

// Check deletion of DISBURSED transactions
Expand Down Expand Up @@ -314,10 +313,10 @@ test('slow path: forward to EUD; remove pending tx', async t => {
'SETTLED entry removed from StatusManger',
);
const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${cctpTxEvidence.txHash}`), [
stringifyWithBigint(cctpTxEvidence),
'OBSERVED',
'FORWARDED',
t.deepEqual(storage.getPureData(`fun.txns.${cctpTxEvidence.txHash}`), [
cctpTxEvidence,
{ status: 'OBSERVED' },
{ status: 'FORWARDED' },
]);

// Check deletion of FORWARDED transactions
Expand Down
31 changes: 15 additions & 16 deletions packages/fast-usdc/test/exos/status-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { TestFn } from 'ava';
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import type { StorageNode } from '@agoric/internal/src/lib-chainStorage.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { stringifyWithBigint } from '@agoric/internal';
import { PendingTxStatus } from '../../src/constants.js';
import { prepareStatusManager } from '../../src/exos/status-manager.js';
import { commonSetup, provideDurableZone } from '../supports.js';
Expand Down Expand Up @@ -56,9 +55,9 @@ test('ADVANCED transactions are published to vstorage', async t => {
await eventLoopIteration();

const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${evidence.txHash}`), [
stringifyWithBigint(evidence),
'ADVANCING',
t.deepEqual(storage.getPureData(`fun.txns.${evidence.txHash}`), [
evidence,
{ status: 'ADVANCING' },
]);
});

Expand Down Expand Up @@ -91,9 +90,9 @@ test('OBSERVED transactions are published to vstorage', async t => {
await eventLoopIteration();

const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${evidence.txHash}`), [
stringifyWithBigint(evidence),
'OBSERVED',
t.deepEqual(storage.getPureData(`fun.txns.${evidence.txHash}`), [
evidence,
{ status: 'OBSERVED' },
]);
});

Expand Down Expand Up @@ -236,10 +235,10 @@ test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
},
]);
await eventLoopIteration();
t.deepEqual(storage.getValues(`fun.txns.${e1.txHash}`), [
stringifyWithBigint(e1),
PendingTxStatus.Advancing,
PendingTxStatus.Advanced,
t.deepEqual(storage.getPureData(`fun.txns.${e1.txHash}`), [
e1,
{ status: 'ADVANCING' },
{ status: 'ADVANCED' },
]);

statusManager.advance(e2);
Expand All @@ -250,10 +249,10 @@ test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
},
]);
await eventLoopIteration();
t.deepEqual(storage.getValues(`fun.txns.${e2.txHash}`), [
stringifyWithBigint(e2),
PendingTxStatus.Advancing,
PendingTxStatus.AdvanceFailed,
t.deepEqual(storage.getPureData(`fun.txns.${e2.txHash}`), [
e2,
{ status: 'ADVANCING' },
{ status: 'ADVANCE_FAILED' },
]);
});

Expand Down Expand Up @@ -326,7 +325,7 @@ test('dequeueStatus returns first (earliest) matched entry', async t => {
PendingTxStatus.Advanced,
'first settled entry deleted',
);
t.is(
t.deepEqual(
entries0?.[1].status,
PendingTxStatus.Observed,
'order of remaining entries preserved',
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/src/storage-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
* Get the values at a sequence node
*
* @param {string} path
* @returns {unknown[]}
* @returns {string[]}
*/
const getValues = path => {
assert(resolvedOptions.sequence);
Expand Down

0 comments on commit 33173f9

Please sign in to comment.