Skip to content

Commit

Permalink
test: validate KREAd character purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert authored and mhofman committed Jun 21, 2024
1 parent e5860fa commit b6bbb79
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
20 changes: 20 additions & 0 deletions a3p-integration/proposals/z:acceptance/create-kread-item-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -euo pipefail

source /usr/src/upgrade-test-scripts/env_setup.sh

OFFER=$(mktemp -t agops.XXX)
agops vaults open --wantMinted 6.00 --giveCollateral 9.0 >|"$OFFER"
agoric wallet send --offer "$OFFER" --from gov1 --keyring-backend="test"


govamount="200000000ubld"
provisionSmartWallet $GOV1ADDR $govamount

KREAD_ITEM_OFFER=$(mktemp -t kreadItem.XXX)
node ./generate-kread-item-request.mjs > $KREAD_ITEM_OFFER
agops perf satisfaction --from $GOV1ADDR --executeOffer $KREAD_ITEM_OFFER --keyring-backend=test

agd query vstorage data published.wallet.$GOV1ADDR.current -o json >& gov1.out
name=`jq '.value | fromjson | .values[2] | fromjson | .body[1:] | fromjson | .purses[1].balance.value.payload[0][0].name ' gov1.out`
test_val $name \"ephemeral_Ace\" "found KREAd character"
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* global process */
import assert from 'assert';
import { execFile } from 'child_process';

const ISTunit = 1_000_000n; // aka displayInfo: { decimalPlaces: 6 }

const id = `KREAd-test-${Date.now()}`;

// poor-man's zx
const $ = cmd => {
const [file, ...args] = cmd.split(' ');

return new Promise((resolve, reject) => {
execFile(file, args, { encoding: 'utf8' }, (err, out) => {
if (err) return reject(err);
resolve(out);
});
});
};

const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);

const fromSmallCapsEntries = txt => {
const { body, slots } = JSON.parse(txt);
const theEntries = zip(JSON.parse(body.slice(1)), slots).map(
([[name, ref], boardID]) => {
const iface = ref.replace(/^\$\d+\./, '');
return [name, { iface, boardID }];
},
);
return Object.fromEntries(theEntries);
};

const brand = fromSmallCapsEntries(
await $('agoric follow -lF :published.agoricNames.brand -o text'),
);
assert(brand.IST);

const slots = []; // XXX global mutable state

const smallCaps = {
Nat: n => `+${n}`,
// XXX mutates obj
ref: obj => {
if (obj.ix) return obj.ix;
const ix = slots.length;
slots.push(obj.boardID);
obj.ix = `$${ix}.Alleged: ${obj.iface}`;
return obj.ix;
},
};

const body = {
method: 'executeOffer',
offer: {
id,
invitationSpec: {
source: 'agoricContract',
instancePath: ['kread'],
callPipe: [['makeMintCharacterInvitation', []]],
},
offerArgs: { name: 'ephemeral_Ace' },
proposal: {
give: {
Price: {
brand: smallCaps.ref(brand.IST),
value: smallCaps.Nat(5n * ISTunit) }
},
},
},
};

const capData = { body: `#${JSON.stringify(body)}`, slots };
const action = JSON.stringify(capData);

console.log(action);
2 changes: 2 additions & 0 deletions a3p-integration/proposals/z:acceptance/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ yarn ava initial.test.js
# test more, in ways that change system state
GLOBIGNORE=initial.test.js
yarn ava ./*.test.js

./create-kread-item-test.sh

0 comments on commit b6bbb79

Please sign in to comment.