Skip to content

Commit

Permalink
test: observe node sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 14, 2024
1 parent 54b46d0 commit e09e2c5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
21 changes: 11 additions & 10 deletions packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 @@ -186,8 +187,8 @@ test('updates status to ADVANCING in happy path', async t => {
await eventLoopIteration();

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

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

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

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

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

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

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

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

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

Expand Down
18 changes: 14 additions & 4 deletions packages/fast-usdc/test/exos/settler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 @@ -234,8 +235,13 @@ test('happy path: disburse to LPs; StatusManager removes tx', async t => {
'SETTLED entry removed from StatusManger',
);
await eventLoopIteration();
const vstorage = t.context.storage.data;
t.is(vstorage.get(`fun.txns.${cctpTxEvidence.txHash}`), 'DISBURSED');
const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${cctpTxEvidence.txHash}`), [
stringifyWithBigint(cctpTxEvidence),
'ADVANCING',
'ADVANCED',
'DISBURSED',
]);
});

test('slow path: forward to EUD; remove pending tx', async t => {
Expand Down Expand Up @@ -302,8 +308,12 @@ test('slow path: forward to EUD; remove pending tx', async t => {
[],
'SETTLED entry removed from StatusManger',
);
const vstorage = t.context.storage.data;
t.is(vstorage.get(`fun.txns.${cctpTxEvidence.txHash}`), 'FORWARDED');
const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${cctpTxEvidence.txHash}`), [
stringifyWithBigint(cctpTxEvidence),
'OBSERVED',
'FORWARDED',
]);
});

test('Settlement for unknown transaction', async t => {
Expand Down
29 changes: 22 additions & 7 deletions packages/fast-usdc/test/exos/status-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -54,8 +55,11 @@ test('ADVANCED transactions are published to vstorage', async t => {
statusManager.advance(evidence);
await eventLoopIteration();

const vstorage = t.context.storage.data;
t.is(vstorage.get(`fun.txns.${evidence.txHash}`), 'ADVANCING');
const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${evidence.txHash}`), [
stringifyWithBigint(evidence),
'ADVANCING',
]);
});

test('observe creates new entry with OBSERVED status', t => {
Expand Down Expand Up @@ -86,8 +90,11 @@ test('OBSERVED transactions are published to vstorage', async t => {
statusManager.observe(evidence);
await eventLoopIteration();

const vstorage = t.context.storage.data;
t.is(vstorage.get(`fun.txns.${evidence.txHash}`), 'OBSERVED');
const { storage } = t.context;
t.deepEqual(storage.getValues(`fun.txns.${evidence.txHash}`), [
stringifyWithBigint(evidence),
'OBSERVED',
]);
});

test('cannot process same tx twice', t => {
Expand Down Expand Up @@ -212,7 +219,7 @@ test('cannot advanceOutcome without ADVANCING entry', t => {
});

test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
const vstorage = t.context.storage.data;
const { storage } = t.context;
const zone = provideDurableZone('status-test');
const statusManager = prepareStatusManager(
zone.subZone('status-manager'),
Expand All @@ -229,7 +236,11 @@ test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
},
]);
await eventLoopIteration();
t.is(vstorage.get(`fun.txns.${e1.txHash}`), PendingTxStatus.Advanced);
t.deepEqual(storage.getValues(`fun.txns.${e1.txHash}`), [
stringifyWithBigint(e1),
PendingTxStatus.Advancing,
PendingTxStatus.Advanced,
]);

statusManager.advance(e2);
statusManager.advanceOutcome(e2.tx.forwardingAddress, e2.tx.amount, false);
Expand All @@ -239,7 +250,11 @@ test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
},
]);
await eventLoopIteration();
t.is(vstorage.get(`fun.txns.${e2.txHash}`), PendingTxStatus.AdvanceFailed);
t.deepEqual(storage.getValues(`fun.txns.${e2.txHash}`), [
stringifyWithBigint(e2),
PendingTxStatus.Advancing,
PendingTxStatus.AdvanceFailed,
]);
});

test('dequeueStatus returns undefined when nothing is settleable', t => {
Expand Down
1 change: 0 additions & 1 deletion packages/fast-usdc/test/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
const marshaller = makeFakeBoard().getReadonlyMarshaller();
const storage = makeFakeStorageKit(
'fun', // Fast USDC Node
{ sequence: false },
);

const { portAllocator, setupIBCProtocol, ibcBridge } = setupFakeNetwork(
Expand Down

0 comments on commit e09e2c5

Please sign in to comment.