Skip to content

Commit

Permalink
test: COA transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Aug 29, 2024
1 parent 408e7bc commit 1425086
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
buildTxPacketString,
parseOutgoingTxPacket,
} from '../../tools/ibc-mocks.js';
import { defaultMockAckMap } from '../ibc-mocks.js';

type TestContext = Awaited<ReturnType<typeof commonSetup>>;

Expand All @@ -27,11 +28,11 @@ test.beforeEach(async t => {

test('send (to addr on same chain)', async t => {
const {
bootstrap,
brands: { ist },
facadeServices: { chainHub },
utils: { inspectDibcBridge },
} = t.context;
const makeTestCOAKit = prepareMakeTestCOAKit(t, bootstrap);
const makeTestCOAKit = prepareMakeTestCOAKit(t, t.context);
const account = await makeTestCOAKit();
t.assert(account, 'account is returned');

Expand All @@ -46,7 +47,7 @@ test('send (to addr on same chain)', async t => {
await E(account).send(toAddress, {
value: 10n,
denom: 'uatom',
} as AmountArg),
}),
undefined,
);

Expand All @@ -57,12 +58,10 @@ test('send (to addr on same chain)', async t => {
{ message: 'ABCI code: 5: error handling packet: see events for details' },
);

// ertp amounts not supported
await t.throwsAsync(
E(account).send(toAddress, ist.make(10n) as AmountArg),
// TODO #9211 register asset before sending
{ message: 'No denomination for brand [object Alleged: IST brand]' },
);
// IST not registered
await t.throwsAsync(E(account).send(toAddress, ist.make(10n) as AmountArg), {
message: 'No denomination for brand [object Alleged: IST brand]',
});

// multi-send (sendAll)
t.is(
Expand All @@ -85,7 +84,7 @@ test('send (to addr on same chain)', async t => {
test('transfer', async t => {
const {
brands: { ist },
bootstrap,
facadeServices: { chainHub },
utils: { inspectDibcBridge },
mocks: { ibcBridge },
} = t.context;
Expand Down Expand Up @@ -139,12 +138,22 @@ test('transfer', async t => {
const transferResp = buildMsgResponseString(MsgTransferResponse, {
sequence: 0n,
});

const uistTransfer = toTransferTxPacket({
...mockIbcTransfer,
token: {
denom: 'uist',
amount: '10',
},
});

return {
[defaultTransfer]: transferResp,
[customTimeoutHeight]: transferResp,
[customTimeoutTimestamp]: transferResp,
[customTimeout]: transferResp,
[customMemo]: transferResp,
[uistTransfer]: transferResp,
};
};
ibcBridge.setMockAck(buildMocks());
Expand All @@ -160,7 +169,7 @@ test('transfer', async t => {
};

t.log('Make account on cosmoshub');
const makeTestCOAKit = prepareMakeTestCOAKit(t, bootstrap);
const makeTestCOAKit = prepareMakeTestCOAKit(t, t.context);
const account = await makeTestCOAKit();

t.log('Send tokens from cosmoshub to noble');
Expand Down Expand Up @@ -258,11 +267,18 @@ test('transfer', async t => {
},
);

t.log("transfer doesn't support ERTP brands yet. see #9211");
t.log('transfer throws if asset is not in its chainHub');
await t.throwsAsync(E(account).transfer(ist.make(10n), mockDestination), {
// TODO #9211 register asset before transfer
message: 'No denomination for brand [object Alleged: IST brand]',
});
chainHub.registerAsset('uist', {
baseDenom: 'uist',
baseName: 'agoric',
brand: ist.brand,
chainName: 'agoric',
});
// uses uistTransfer mock above
await E(account).transfer(ist.make(10n), mockDestination);

t.log('transfer timeout error recieved and handled from the bridge');
await t.throwsAsync(
Expand All @@ -286,8 +302,7 @@ test('transfer', async t => {
});

test('not yet implemented', async t => {
const { bootstrap } = await commonSetup(t);
const makeTestCOAKit = prepareMakeTestCOAKit(t, bootstrap);
const makeTestCOAKit = prepareMakeTestCOAKit(t, t.context);
const account = await makeTestCOAKit();
const mockAmountArg: AmountArg = { value: 10n, denom: 'uatom' };

Expand Down
28 changes: 10 additions & 18 deletions packages/orchestration/test/exos/make-test-coa-kit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Far } from '@endo/far';
/* eslint-disable jsdoc/require-param -- ts types */
import { heapVowE as E } from '@agoric/vow/vat.js';
import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
import { Far } from '@endo/far';
import type { ExecutionContext } from 'ava';
import { commonSetup } from '../supports.js';
import { prepareCosmosOrchestrationAccount } from '../../src/exos/cosmos-orchestration-account.js';
import { makeChainHub } from '../../src/exos/chain-hub.js';
import { commonSetup } from '../supports.js';

/**
* A testing utility that creates a (Cosmos)ChainAccount and makes a
Expand All @@ -13,25 +13,14 @@ import { makeChainHub } from '../../src/exos/chain-hub.js';
*
* Helps reduce boilerplate in test files, and retains testing context through
* parameterized endowments.
*
* @param t
* @param bootstrap
* @param opts
* @param opts.zcf
*/
export const prepareMakeTestCOAKit = (
t: ExecutionContext,
bootstrap: Awaited<ReturnType<typeof commonSetup>>['bootstrap'],
{ bootstrap, facadeServices, utils }: Awaited<ReturnType<typeof commonSetup>>,
{ zcf = Far('MockZCF', {}) } = {},
) => {
const {
cosmosInterchainService,
marshaller,
rootZone,
timer,
vowTools,
agoricNames,
} = bootstrap;
const { cosmosInterchainService, marshaller, rootZone, timer, vowTools } =
bootstrap;

const { makeRecorderKit } = prepareRecorderKitMakers(
rootZone.mapStore('CosmosOrchAccountRecorder'),
Expand All @@ -41,7 +30,7 @@ export const prepareMakeTestCOAKit = (
const makeCosmosOrchestrationAccount = prepareCosmosOrchestrationAccount(
rootZone.subZone('CosmosOrchAccount'),
{
chainHub: makeChainHub(agoricNames, vowTools),
chainHub: facadeServices.chainHub,
makeRecorderKit,
timerService: timer,
vowTools,
Expand Down Expand Up @@ -83,6 +72,9 @@ export const prepareMakeTestCOAKit = (
},
);

t.log('register Agoric chain and BLD in ChainHub');
utils.registerAgoricBld();

return holder;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('portfolio holder kit behaviors', async t => {
},
});

const makeTestCOAKit = prepareMakeTestCOAKit(t, common.bootstrap, {
const makeTestCOAKit = prepareMakeTestCOAKit(t, common, {
zcf: mockZcf,
});
const makeTestLOAKit = prepareMakeTestLOAKit(t, common, { zcf: mockZcf });
Expand Down

0 comments on commit 1425086

Please sign in to comment.