Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Test Suite Integrity and Lint Compliance #133

Merged
merged 7 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,9 @@ jobs:
all:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: "18"
- name: yarn install
run: yarn
# commenting the lint process out below for purpose of seeing test code run to completion
- name: yarn lint
run: yarn lint
# - name: yarn build
# run: yarn build
- name: yarn test
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: corepack enable
- run: yarn install
- name: run tests
run: yarn test
- name: yarn test:e2e
run: yarn test:e2e
5 changes: 3 additions & 2 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^46.4.3",
"eslint-plugin-prettier": "^5.0.0",
"execa": "^9.2.0",
"execa": "^9.5.1",
"fs-extra": "^11.2.0",
"immutable": "5.0.0-beta.5",
"import-meta-resolve": "^2.2.1",
Expand Down Expand Up @@ -77,7 +77,8 @@
"ava": {
"concurrency": 1,
"serial": true,
"failFast": true,
"timeout": "30s",
"failFast": false,
"tap": true,
"extensions": [
"ts",
Expand Down
285 changes: 285 additions & 0 deletions contract/src/airdrop.local.proposal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
// @ts-check
import { E } from '@endo/far';
import { Fail } from '@endo/errors';
import { makeMarshal } from '@endo/marshal';
import { makeTracer } from '@agoric/internal';
import { installContract } from './platform-goals/start-contract.js';
import './types.js';

const contractName = 'tribblesAirdrop';

const trace = makeTracer('startAirdrop script');
/** @import { StartArgs } from './platform-goals/start-contract.js'; */
const AIRDROP_TIERS_STATIC = [9000n, 6500n, 3500n, 1500n, 750n].map(
x => x * 1_000_000n,
);

/**
* @typedef {{
* startTime: bigint;
* initialPayoutValues: any;
* targetNumberOfEpochs: number;
* targetEpochLength: bigint;
* targetTokenSupply: bigint;
* tokenName: string;
* }} CustomContractTerms
*/

export const defaultCustomTerms = {
startTime: 0n,
initialPayoutValues: harden(AIRDROP_TIERS_STATIC),
targetNumberOfEpochs: 5,
targetEpochLength: 12_000n / 2n,
targetTokenSupply: 10_000_000n * 1_000_000n,
tokenName: 'Tribbles',
};

export const makeTerms = (terms = {}) => ({
...defaultCustomTerms,
...terms,
});
harden(makeTerms);

// vstorage paths under published.*
const BOARD_AUX = 'boardAux';

const marshalData = makeMarshal(_val => Fail`data only`);

/**
* @import {ERef} from '@endo/far';
* @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
* @import {BootstrapManifest} from '@agoric/vats/src/core/lib-boot.js';
*/

/**
* Make a storage node for auxilliary data for a value on the board.
*
* @param {ERef<StorageNode>} chainStorage
* @param {string} boardId
*/
const makeBoardAuxNode = async (chainStorage, boardId) => {
const boardAux = E(chainStorage).makeChildNode(BOARD_AUX);
return E(boardAux).makeChildNode(boardId);
};

const publishBrandInfo = async (chainStorage, board, brand) => {
trace('publishing info for brand', brand);
const [id, displayInfo] = await Promise.all([
E(board).getId(brand),
E(brand).getDisplayInfo(),
]);
trace('E(board).getId(brand)', id);
const node = makeBoardAuxNode(chainStorage, id);
trace('boardAuxNode ####', node);
const aux = marshalData.toCapData(harden({ displayInfo }));

const stringifiedAux = JSON.stringify(aux);
trace('JSON.stringify(aux)', stringifiedAux);
await E(node).setValue(stringifiedAux);
};

// const prepareForExecutionEnv = ()
/**
* Core eval script to start contract
*
* @param {BootstrapPowers } permittedPowers
* @param {*} config
*
* @typedef {{
* brand: PromiseSpaceOf<{ Tribbles: import('@agoric/ertp/src/types.js').Brand }>;
* issuer: PromiseSpaceOf<{ Tribbles: import('@agoric/ertp/src/types.js').Issuer }>;
* instance: PromiseSpaceOf<{ [contractName]: Instance }>
* }} AirdropSpace
*/

/**
* Core eval script to start contract
*
* @param {BootstrapPowers & AirdropSpace} powers
* @param {{
* options: { tribblesAirdrop: { bundleID: string }; customTerms: any };
* }} config
* XXX export AirdropTerms record from contract
*/
export const startAirdrop = async (powers, config) => {
trace('######## inside startAirdrop ###########');
trace('config ::::', config);
trace('----------------------------------');
trace('powers::', powers);
trace('powers.installation', powers.installation.consume);
trace('powers.installation', powers.installation.consume[contractName]);
const {
consume: {
namesByAddressAdmin,
namesByAddress,
// bankManager,
board,
chainTimerService,
chainStorage,
// startUpgradable,
zoe,
},
instance: {
produce: { [contractName]: produceInstance },
},
issuer: {
consume: { IST: istIssuer },
produce: { Tribbles: produceTribblesIssuer },
},
brand: {
consume: { IST: istBrand },
produce: { Tribbles: produceTribblesBrand },
},
} = powers;

const [issuerIST, feeBrand, timer] = await Promise.all([
istIssuer,
istBrand,
chainTimerService,
]);

const { customTerms } = config.options;

/** @type {CustomContractTerms} */
const terms = {
...customTerms,
feeAmount: harden({
brand: feeBrand,
value: 5n,
}),
};
assert(
customTerms?.merkleRoot,
'can not start contract without merkleRoot???',
);

const installation = await installContract(powers, {
name: contractName,
bundleID: config.options.tribblesAirdrop.bundleID,
});
const startOpts = {
installation,
label: contractName,
name: contractName,
terms,
issuerKeywordRecord: {
Fee: issuerIST,
},
issuerNames: ['Tribbles'],
privateArgs: harden({
timer,
}),
};
trace('BEFORE astartContract(permittedPowers, startOpts);', { startOpts });

const { instance, creatorFacet } = await E(zoe).startInstance(
installation,
startOpts.issuerKeywordRecord,
startOpts.terms,
startOpts.privateArgs,
startOpts.label,
);
// const { instance, creatorFacet } = await E(zoe).startInstance(
// bundle,
// startOpts.issuerKeywordRecord,
// startOpts.terms,
// startOpts.privateArgs,
// startOpts.label,
// );
trace('contract installation started');
trace(instance);
const instanceTerms = await E(zoe).getTerms(instance);
trace('instanceTerms::', instanceTerms);
const {
brands: { Tribbles: tribblesBrand },
issuers: { Tribbles: tribblesIssuer },
} = instanceTerms;

produceInstance.reset();
produceInstance.resolve(instance);

produceTribblesBrand.reset();
produceTribblesIssuer.reset();
produceTribblesBrand.resolve(tribblesBrand);
produceTribblesIssuer.resolve(tribblesIssuer);

// Sending invitation for pausing contract to a specific wallet
// TODO: add correct wallet address
const adminWallet = 'agoric1jng25adrtpl53eh50q7fch34e0vn4g72j6zcml';
await E(namesByAddressAdmin).reserve(adminWallet);
const adminDepositFacet = E(namesByAddress).lookup(
adminWallet,
'depositFacet',
);

await E(creatorFacet).makePauseContractInvitation(adminDepositFacet);

// prepareForExecutionEnv(creatorFacet, tribblesBrand, tribblesIssuer, tribblesMint, chainStorage, board)
// Add utribbles token to vbank
// const tribblesMint = await E(creatorFacet).getBankAssetMint();

// await E(bankManager).addAsset(
// 'utribbles',
// 'Tribbles',
// 'Tribbles Intersubjective Token',
// harden({
// issuer: tribblesIssuer,
// brand: tribblesBrand,
// mint: tribblesMint,
// }),
// );
await publishBrandInfo(chainStorage, board, tribblesBrand);
trace('deploy script complete.');
};

/** @type {import('@agoric/vats/src/core/lib-boot').BootstrapManifest} */
const airdropManifest = harden({
[startAirdrop.name]: {
consume: {
namesByAddress: true,
namesByAddressAdmin: true,
bankManager: true,
board: true,
chainStorage: true,
chainTimerService: true,
agoricNames: true,
brandAuxPublisher: true,
startUpgradable: true, // to start contract and save adminFacet
zoe: true, // to get contract terms, including issuer/brand,
},
installation: {
consume: { [contractName]: true },
produce: { [contractName]: true },
},
issuer: {
consume: { IST: true, Tribbles: true },
produce: { Tribbles: true },
},
brand: {
consume: { IST: true, Tribbles: true },
produce: { Tribbles: true },
},
instance: { produce: { [contractName]: true } },
},
});

export const permit = Object.values(airdropManifest)[0];

export const main = (
permittedPowers,

config = {
options: Fail`missing options config`,
},
) => {
startAirdrop(permittedPowers, config);
};

export const getManifestForAirdrop = ({ restoreRef }, { airdropRef }) => {
return harden({
manifest: airdropManifest,
installations: {
airdrop: restoreRef(airdropRef),
},
});
};
Loading