Skip to content

Commit

Permalink
feat(reset-state): add command to ag-solo to reset SwingSet
Browse files Browse the repository at this point in the history
Note that the ag-cosmos-helper state is not reset.
  • Loading branch information
michaelfig committed Feb 3, 2020
1 parent aa7d960 commit 233c0ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 0 additions & 9 deletions packages/cosmic-swingset/lib/ag-solo/init-basedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ export default function initBasedir(
}
fs.symlinkSync(nm, path.join(basedir, 'node_modules'));

const mailboxStateFile = path.resolve(basedir, 'swingset-mailbox-state.json');
fs.writeFileSync(mailboxStateFile, `{}\n`);
const kernelStateFile = path.resolve(
basedir,
'swingset-kernel-state.jsonlines',
);
// this contains newline-terminated lines of JSON.stringify(['key', 'value'])
fs.writeFileSync(kernelStateFile, ``);

// cosmos-sdk keypair
if (egresses.includes('cosmos')) {
const agchServerDir = path.join(basedir, 'ag-cosmos-helper-statedir');
Expand Down
5 changes: 5 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { insist } from './insist';
// Start a network service
import bundle from './bundle';
import initBasedir from './init-basedir';
import resetState from './reset-state';
import setGCIIngress from './set-gci-ingress';
import setFakeChain from './set-fake-chain';
import start from './start';
Expand Down Expand Up @@ -64,6 +65,7 @@ start
const subdir = subArgs[1];
insist(basedir !== undefined, 'you must provide a BASEDIR');
initBasedir(basedir, webport, webhost, subdir, egresses.split(','));
await resetState(basedir);
// console.error(
// `Run '(cd ${basedir} && ${progname} start)' to start the vat machine`,
// );
Expand All @@ -83,6 +85,9 @@ start
const basedir = insistIsBasedir();
const withSES = true;
await start(basedir, withSES, argv.slice(1));
} else if (argv[0] === 'reset-state') {
const basedir = insistIsBasedir();
await resetState(basedir);
} else if (argv[0] === 'bundle') {
await bundle(insistIsBasedir, argv.slice(1));
} else if (argv[0] === 'upload-contract') {
Expand Down
13 changes: 13 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/reset-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from 'path';
import fs from 'fs';

export default async function resetState(basedir) {
const mailboxStateFile = path.resolve(basedir, 'swingset-mailbox-state.json');
fs.writeFileSync(mailboxStateFile, `{}\n`);
const kernelStateFile = path.resolve(
basedir,
'swingset-kernel-state.jsonlines',
);
// this contains newline-terminated lines of JSON.stringify(['key', 'value'])
fs.writeFileSync(kernelStateFile, ``);
}

0 comments on commit 233c0ff

Please sign in to comment.