Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('confineVatSource', t => {
const s = SES.makeSESRootRealm({ consoleMode: 'allow' });
const s1code = funcToSource(s1);
// console.log(`source: ${s1code}`);
const req = s.makeRequire({ '@agoric/nat': Nat, '@agoric/harden': true });
const e = confineVatSource(s, req, `${s1code}`).default();
t.equal(e.increment(), 1);
t.equal(e.increment(), 2);
t.equal(e.decrement(), 1);
t.end();
});
test('marshal', async t => {
const s = SES.makeSESRootRealm({
consoleMode: 'allow',
errorStackMode: 'allow',
});
const code = await bundleCode(require.resolve('../src/vat/webkey'));
const req = s.makeRequire({ '@agoric/nat': Nat, '@agoric/harden': true });
const e = confineVatSource(s, req, code);
const endowments = makeVatEndowments(s, req, null, null);
/* eslint-disable-next-line no-unused-vars */
const { hash58: hash58Endowed } = endowments;
function helpers() {
/* eslint-disable-next-line global-require, import/no-unresolved */
const harden = require('@agoric/harden');
function serializer(x) {
console.log(x);
}
test('hash58', t => {
const s = SES.makeSESRootRealm({
consoleMode: 'allow',
errorStackMode: 'allow',
});
const req = s.makeRequire({ '@agoric/nat': Nat, '@agoric/harden': true });
const e = makeVatEndowments(s, req, null, null);
// test vectors from python and electrum/lib/address.py Base58 class
// Base58.encode(hashlib.sha256(s).digest()[:16])
t.equal(e.hash58(''), 'V7jseQevszwMPhi4evidTR');
t.equal(e.hash58(''), 'V7jseQevszwMPhi4evidTR'); // stable
t.equal(e.hash58('a'), 'S1yrYnjHbfbiTySsN9h1eC');
let xyz100 = '';
for (let i = 0; i < 100; i += 1) {
xyz100 += 'xyz';
}
t.equal(e.hash58(xyz100), 'LkLiePjfKWZzhQgmcEPT8j');
t.end();
async function snapEval (argv) {
const { bundle } = argv
await validateFilePath(bundle)
try {
const s = SES.makeSESRootRealm({consoleMode: 'allow', errorStackMode: 'allow', mathRandomMode: 'allow'})
const result = s.evaluate(fs.readFileSync(bundle), {
// TODO: mock wallet properly
wallet: { registerRpcMessageHandler: () => true },
console
})
if (!result) {
throw new Error(`SES.evaluate returned falsy value.`)
}
console.log(`Eval Success: evaluated '${bundle}' in SES!`)
} catch (err) {
logError(`Snap evaluation error: ${err.message}`, err)
process.exit(1)
}
return true
}
export function makeRealm() {
const mode = { consoleMode: 'allow' };
// mode.errorStackMode = 'allow'; // debug only
const s = SES.makeSESRootRealm(mode);
return s;
}
function createModule (code, opts = {}) {
// TODO: ensure args are valid
// TODO: find good default
opts.memoryLimit = opts.memoryLimit || 10e6
let memoryMeter = new MemoryMeter()
let realm = makeSESRootRealm({
consoleMode: opts.allowConsole ? 'allow' : false
})
// run prelude code inside realm
let {
module,
functionConstructors,
iteratedMethods,
RegExp,
stringRepeat
} = realm.evaluate(prelude)
let aborting = false
let burnHandler = (value) => {
// throw if a previous burn handler already errored
// TODO: find better way to abort?
import PQueue from 'p-queue'
import mkdirp from 'mkdirp'
import makeRootBotEndowments from './root-bot-mixin'
import makeUtilsEndowments from './mixins/utils'
const readdir = util.promisify(fs.readdir)
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
class SesBot extends EventEmitter {}
const sesBot = new SesBot()
const debugLog = debug('ses-bot')
const r = SES.makeSESRootRealm()
function buildBotKernelSrc () {
let def, log, debugLog
function kernel () {
let messageCounter = 0
let processes = []
let state = []
let refs = []
let storageDir
const definitions = {
setStorageDir: dir => storageDir = dir,
register,
loadBotsFromDisk,
send,