From 8899a4d8733d4c3977f5be7f9a2b4b785c6d1c5d Mon Sep 17 00:00:00 2001 From: Jake O'Shannessy Date: Tue, 9 Apr 2019 18:01:45 +1000 Subject: [PATCH] Constructor bootstrap proof-of-concept. This commit gives TestKernel a constructor which takes an initial entry procedure. This required test changes throughout. The implementation will need to be updated to have a better architecture, but this implements the concepts and updates tests for compatibility. The next steps will be to move it to a level lower then TestKernel and abstract some of the initial cap setup. The concept is documented in in issue #130. --- contracts/CapabilityManager.sol | 9 ++ contracts/Kernel.sol | 6 +- contracts/KernelStorage.sol | 6 +- contracts/TestKernel.sol | 36 ++++++- migrations/1_initial_migration.js | 3 - test/factory.js | 32 +++--- test/testutils.js | 43 +++++--- test/withentryproc/procedures.js | 6 +- test/withentryproc/syscalls/acc_call.js | 128 ++++++++++++------------ test/withentryproc/syscalls/call.js | 91 ++++++++--------- test/withentryproc/syscalls/delete.js | 56 +++++------ test/withentryproc/syscalls/entry.js | 6 +- test/withentryproc/syscalls/log.js | 64 ++++++------ test/withentryproc/syscalls/register.js | 64 ++---------- test/withentryproc/syscalls/write.js | 13 ++- test/withoutentryproc/procedures.js | 105 +++++++++++-------- test/withoutentryproc/syscalls/call.js | 66 ++++++++---- test/withoutentryproc/syscalls/log.js | 48 ++++++--- test/withoutentryproc/syscalls/write.js | 9 +- 19 files changed, 433 insertions(+), 358 deletions(-) diff --git a/contracts/CapabilityManager.sol b/contracts/CapabilityManager.sol index 094164d..156ae0b 100644 --- a/contracts/CapabilityManager.sol +++ b/contracts/CapabilityManager.sol @@ -5,6 +5,15 @@ import "./ProcedureTable.sol"; contract CapabilityManager is ProcedureTable { + // CAPABILITY_TYPES + uint8 constant CAP_PROC_CALL = 3; + uint8 constant CAP_PROC_REGISTER = 4; + uint8 constant CAP_PROC_DELETE = 5; + uint8 constant CAP_PROC_ENTRY = 6; + uint8 constant CAP_STORE_WRITE = 7; + uint8 constant CAP_LOG = 8; + uint8 constant CAP_ACC_CALL = 9; + function checkRegisterCapability(uint192 currentProcedure, bytes24 procedureKey, uint256 reqCapIndex) internal view returns (bool) { uint256 capType = CAP_PROC_REGISTER; diff --git a/contracts/Kernel.sol b/contracts/Kernel.sol index b59cc15..f6ddc4e 100644 --- a/contracts/Kernel.sol +++ b/contracts/Kernel.sol @@ -339,7 +339,8 @@ contract Kernel is Factory, ProcedureTable, CapabilityManager, IKernel { 0) // We need to restore the previous procedure as the current // procedure, this can simply be on the stack - sstore(0xffffff0300000000000000000000000000000000000000000000000000000000,div(previousProcedure,exp(0x100,8))) + // TODO: remove direct reference to storage key here + sstore(0xffffffff03000000000000000000000000000000000000000000000000000000,div(previousProcedure,exp(0x100,8))) if status { let returnLength := returndatasize @@ -893,7 +894,8 @@ contract Kernel is Factory, ProcedureTable, CapabilityManager, IKernel { status := callcode(gas,procedureAddress,0,ins,inl,0,0) // Zero-out the currentProcedure - sstore(0xffffff0300000000000000000000000000000000000000000000000000000000,0) + // TODO: needs to use the KernelStorage abstraction + sstore(0xffffffff03000000000000000000000000000000000000000000000000000000,0) // copy the return data to memory based on its size if iszero(status) { let retSize := add(0x1,returndatasize) diff --git a/contracts/KernelStorage.sol b/contracts/KernelStorage.sol index 79db2ce..52dbc0c 100644 --- a/contracts/KernelStorage.sol +++ b/contracts/KernelStorage.sol @@ -16,17 +16,17 @@ contract KernelStorage { // Returns the storage key that holds the entry procedure name. function _getPointerEntryProcedure() pure internal returns (uint256) { - return 0xffffff0400000000000000000000000000000000000000000000000000000000; + return 0xffffffff04000000000000000000000000000000000000000000000000000000; } // Returns the storage key that holds the current procedure name. function _getPointerCurrentProcedure() pure internal returns (uint256) { - return 0xffffff0300000000000000000000000000000000000000000000000000000000; + return 0xffffffff03000000000000000000000000000000000000000000000000000000; } // Returns the storage key that holds the kernel address. function _getPointerKernelAddress() pure internal returns (uint256) { - return 0xffffff0200000000000000000000000000000000000000000000000000000000; + return 0xffffffff02000000000000000000000000000000000000000000000000000000; } // Return the storage key that holds the number of procedures in the list. diff --git a/contracts/TestKernel.sol b/contracts/TestKernel.sol index ac21308..b67a4a7 100644 --- a/contracts/TestKernel.sol +++ b/contracts/TestKernel.sol @@ -4,12 +4,44 @@ import "./Kernel.sol"; // Kernel Interface for Testing contract TestKernel is Kernel { - constructor() public { - // kernelAddress = WhatIsMyAddress.get(); + constructor(address initProcAddress) public { // This is an example kernel global variable for testing. assembly { sstore(0x8000,3) } + uint256[] memory caps = new uint256[](21); + // CAP_PROC_CALL = 3; + caps[0] = 3; // capSize + caps[1] = 3; // capType + caps[2] = 0; // capIndex + // CAP_PROC_REGISTER = 4; + caps[3] = 3; // capSize + caps[4] = 4; // capType + caps[5] = 0; // capIndex + // CAP_PROC_DELETE = 5; + caps[6] = 3; // capSize + caps[7] = 5; // capType + caps[8] = 0; // capIndex + // CAP_PROC_ENTRY = 6; + caps[9] = 3; // capSize + caps[10] = 6; // capType + caps[11] = 0; // capIndex + // CAP_STORE_WRITE = 7; + caps[12] = 3; // capSize + caps[13] = 7; // capType + caps[14] = 0; // capIndex + // CAP_LOG = 8; + caps[15] = 3; // capSize + caps[16] = 8; // capType + caps[17] = 0; // capIndex + // CAP_ACC_CALL = 9; + caps[18] = 3; // capSize + caps[19] = 9; // capType + caps[20] = 0; // capIndex + bytes24 procName = bytes24("init"); + // TODO: Using insert directly skips validation, we shouldn't do that + insert(procName, initProcAddress, caps); + _setEntryProcedureRaw(uint192(procName)); } function testGetter() public view returns(uint256) { diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js index 46a6da5..979efce 100644 --- a/migrations/1_initial_migration.js +++ b/migrations/1_initial_migration.js @@ -3,7 +3,4 @@ var Factory = artifacts.require("./Factory.sol"); var Kernel = artifacts.require("./TestKernel.sol"); module.exports = function(deployer) { - deployer.deploy(Migrations); - deployer.deploy(Factory); - deployer.deploy(Kernel); }; diff --git a/test/factory.js b/test/factory.js index b41389e..e1dc404 100644 --- a/test/factory.js +++ b/test/factory.js @@ -35,7 +35,7 @@ contract('Factory', function (accounts) { describe('.validate()', async function() { it('should accept valid contract', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); let result = await factory.validate(testutils.trimSwarm(Valid.Adder.bytecode), {from: accounts[0]}); const tx = await factory.validate.sendTransaction(testutils.trimSwarm(Valid.Adder.bytecode), {from: accounts[0]}); const receipt = web3.eth.getTransactionReceipt(tx); @@ -44,32 +44,32 @@ contract('Factory', function (accounts) { }) it('should reject a contract if it uses CREATE', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); let result = await factory.validate(testutils.trimSwarm(Invalid.Create.bytecode), {from: accounts[0]}); assert.equal(8, result.toNumber()); }) it('should reject a contract if it uses CALL', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); let result = await factory.validate(testutils.trimSwarm(Invalid.Call.bytecode), {from: accounts[0]}); assert.equal(9, result.toNumber()); }) it('should reject a contract if it uses CALLCODE', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); let result = await factory.validate(testutils.trimSwarm(Invalid.Callcode.bytecode), {from: accounts[0]}); assert.equal(10, result.toNumber()); }) it('should reject a contract if it uses DELEGATECALL', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); let result = await factory.validate(testutils.trimSwarm(Invalid.Delegatecall.bytecode), {from: accounts[0]}); assert.equal(11, result.toNumber()); }) it('should reject a contract if it uses SELFDESTRUCT', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); let result = await factory.validate(testutils.trimSwarm(Invalid.Suicide.bytecode), {from: accounts[0]}); assert.equal(13, result.toNumber()); }) @@ -77,21 +77,21 @@ contract('Factory', function (accounts) { describe('.validateContract()', async function() { it('should accept valid contract', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Valid.Adder); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(0, result.toNumber()); }) it('should accept valid contract with system calls (write)', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Valid.SysCallTestWrite); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(result.toNumber(), 0); }) it('should accept valid contract with system calls (call)', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Valid.SysCallTestCall); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); const tx = await factory.validateContract.sendTransaction(deployedContract.address, {from: accounts[0]}); @@ -101,35 +101,35 @@ contract('Factory', function (accounts) { }) it('should accept valid contract with system calls (log)', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Valid.SysCallTestLog); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(result.toNumber(), 0); }) it('should reject a contract if it uses CREATE', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Invalid.Create); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(8, result.toNumber()); }) it('should reject a contract if it uses CALL', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Invalid.Call); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(9, result.toNumber()); }) it('should reject a contract if it uses CALLCODE', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Invalid.Callcode); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(10, result.toNumber()); }) it('should reject a contract if it uses DELEGATECALL', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Invalid.Delegatecall); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(11, result.toNumber()); @@ -137,14 +137,14 @@ contract('Factory', function (accounts) { it('should reject a contract if it uses SELFDESTRUCT', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(Invalid.Suicide); let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(13, result.toNumber()); }) it('should reject a contract if it uses SSTORE', async function () { - let factory = await Factory.deployed(); + let factory = await Factory.new(); const deployedContract = await testutils.deployedTrimmed(TestWrite) let result = await factory.validateContract(deployedContract.address, {from: accounts[0]}); assert.equal(2, result.toNumber()); diff --git a/test/testutils.js b/test/testutils.js index 26614a2..340baea 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -1,22 +1,37 @@ const beakerlib = require("../beakerlib"); const BasicEntryProcedure = artifacts.require('BasicEntryProcedure.sol'); +const Kernel = artifacts.require('./TestKernel.sol') -async function installEntryProc(kernel) { - const entryProcName = "EntryProcedure"; - const capArrayEntryProc = beakerlib.Cap.toInput([ - new beakerlib.WriteCap(0x8001,2), - new beakerlib.LogCap([]), - // Call or register any procedure key - new beakerlib.CallCap(0,""), - new beakerlib.RegisterCap(0,"") - ]); +// Deploy a kernel and install the example entry procedure +async function deployTestKernel() { + // First deploy the entry procedure that will be used to bootstrap the + // system. const deployedEntryProc = await deployedTrimmed(BasicEntryProcedure); - // Install the entry procedure - const regTX = await kernel.registerAnyProcedure(entryProcName, deployedEntryProc.address, capArrayEntryProc); - const setEntryTX = await kernel.setEntryProcedure(entryProcName); - return [regTX, setEntryTX]; + + // Deploy the kernel, specifying the previsouly deployed procedure as the + // first entry procedure. This will be named "init ". + let kernel; + try { + kernel = await Kernel.new(deployedEntryProc.address); + } catch (e) { + throw new Error(e); + } + + const procedures1Raw = await kernel.listProcedures.call(); + const procedures1 = procedures1Raw.map(web3.toAscii) + .map(s => s.replace(/\0.*$/, '')); + assert(procedures1.length == 1, + "The kernel should initially have a single procedure procedures"); + const initEntryProc = await kernel.getEntryProcedure.call(); + // Check that the entry procedure was correctly installed. + assert.strictEqual(web3.toAscii(initEntryProc).replace(/\0.*$/, ''), "init", + "The kernel should have an entry procedure registered as \"init\""); + // Check that the capabilities are correct + // TODO: we want to ensure that the maximal caps are provided + // await checkCaps(kernel, "init", []); + return kernel; } -exports.installEntryProc = installEntryProc; +exports.deployTestKernel = deployTestKernel; function trimSwarm(bytecode) { const size = bytecode.length; diff --git a/test/withentryproc/procedures.js b/test/withentryproc/procedures.js index 31a950b..8098f6f 100644 --- a/test/withentryproc/procedures.js +++ b/test/withentryproc/procedures.js @@ -36,10 +36,10 @@ contract('Kernel with entry procedure', function (accounts) { describe('A()', function () { it('A() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + // Install the entry procedure - await testutils.installEntryProc(kernel); + const kernel = await testutils.deployTestKernel(); // We want to send an empty transaction. With an empty // transaction, the following things should occur: // 1. The payload should get forwared to the entry @@ -66,4 +66,4 @@ contract('Kernel with entry procedure', function (accounts) { }) }) }) -}) \ No newline at end of file +}) diff --git a/test/withentryproc/syscalls/acc_call.js b/test/withentryproc/syscalls/acc_call.js index 5a3a4ba..8aefdae 100644 --- a/test/withentryproc/syscalls/acc_call.js +++ b/test/withentryproc/syscalls/acc_call.js @@ -52,7 +52,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -65,7 +66,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -116,7 +116,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -132,7 +133,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -191,7 +191,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -207,7 +208,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -258,7 +258,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -274,7 +275,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -329,7 +329,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -359,7 +360,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -405,7 +405,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract, retrieve correct testNum and transfer 1 wei from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -435,7 +436,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -478,7 +478,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -519,7 +520,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -567,7 +567,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -608,7 +609,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -663,7 +663,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -693,7 +694,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -739,7 +739,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -769,7 +770,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -812,7 +812,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -853,7 +854,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -901,7 +901,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -942,7 +943,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1002,7 +1002,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1018,7 +1019,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1068,7 +1068,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1084,7 +1085,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1142,7 +1142,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1158,7 +1159,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1208,7 +1208,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1224,7 +1225,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1289,7 +1289,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1302,7 +1303,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1351,7 +1351,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1367,7 +1368,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1425,7 +1425,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1441,7 +1442,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1490,7 +1490,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -1506,7 +1507,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1559,7 +1559,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -1589,7 +1590,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1633,7 +1633,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract, retrieve correct testNum and transfer 1 wei from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -1663,7 +1664,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1705,7 +1705,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -1746,7 +1747,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1793,7 +1793,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -1834,7 +1835,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1888,7 +1888,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should be able to call a contract and retrieve correct testNum from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -1918,7 +1919,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -1962,7 +1962,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei from specified contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -1992,7 +1993,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -2034,7 +2034,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -2075,7 +2076,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -2122,7 +2122,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei from another contract', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Deploy a regular Ethereum contract that is not related to // Beaker. @@ -2163,7 +2164,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -2222,7 +2222,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -2238,7 +2239,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -2287,7 +2287,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -2303,7 +2304,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -2360,7 +2360,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract and retrieve correct testNum', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 0; const deployedContract = await testutils.deployedTrimmed(contract); @@ -2376,7 +2377,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. @@ -2425,7 +2425,8 @@ contract('Kernel with entry procedure', function (accounts) { it('Should fail to call a contract, retrieve correct testNum and transfer 1 wei', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const amount = 1; const deployedContract = await testutils.deployedTrimmed(contract); @@ -2441,7 +2442,6 @@ contract('Kernel with entry procedure', function (accounts) { const originalValue = await kernel.testGetter.call(); assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); - await testutils.installEntryProc(kernel); // Test that the AccCall test procedure is correctly installed // by querying a value from it. diff --git a/test/withentryproc/syscalls/call.js b/test/withentryproc/syscalls/call.js index 181f9a2..b020b10 100644 --- a/test/withentryproc/syscalls/call.js +++ b/test/withentryproc/syscalls/call.js @@ -43,7 +43,8 @@ contract('Kernel with entry procedure', function (accounts) { it('A() should succeed when given general cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -61,7 +62,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -81,7 +81,8 @@ contract('Kernel with entry procedure', function (accounts) { it('A() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -98,7 +99,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupy the first 24 bytes, so must be // padded @@ -123,7 +123,8 @@ contract('Kernel with entry procedure', function (accounts) { it('A() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -141,7 +142,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -160,7 +160,8 @@ contract('Kernel with entry procedure', function (accounts) { it('A() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -178,7 +179,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -197,7 +197,8 @@ contract('Kernel with entry procedure', function (accounts) { it('A() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -215,7 +216,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -240,7 +240,8 @@ contract('Kernel with entry procedure', function (accounts) { it('B() should succeed when a general given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -259,7 +260,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -277,7 +277,8 @@ contract('Kernel with entry procedure', function (accounts) { it('B() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -295,7 +296,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -314,7 +314,8 @@ contract('Kernel with entry procedure', function (accounts) { it('B() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -332,7 +333,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -351,7 +351,8 @@ contract('Kernel with entry procedure', function (accounts) { it('B() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -369,7 +370,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -388,7 +388,8 @@ contract('Kernel with entry procedure', function (accounts) { it('B() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -406,7 +407,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -431,7 +431,8 @@ contract('Kernel with entry procedure', function (accounts) { it('C() should succeed when given a general cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -450,7 +451,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -469,7 +469,8 @@ contract('Kernel with entry procedure', function (accounts) { it('C() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -487,7 +488,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -506,7 +506,8 @@ contract('Kernel with entry procedure', function (accounts) { it('C() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -525,7 +526,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -544,7 +544,8 @@ contract('Kernel with entry procedure', function (accounts) { it('C() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -563,7 +564,6 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(originalValue.toNumber(), 3, "test incorrectly set up: initial value should be 3"); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -587,7 +587,8 @@ contract('Kernel with entry procedure', function (accounts) { it('E() should succeed when given general cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -602,7 +603,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx2 = await kernel.registerAnyProcedure(testProcName, deployedTestContract.address, beakerlib.Cap.toInput([cap2, cap1])); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -619,7 +619,8 @@ contract('Kernel with entry procedure', function (accounts) { it('E() should succeed when given specific cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -635,7 +636,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx2 = await kernel.registerAnyProcedure(testProcName, deployedTestContract.address, beakerlib.Cap.toInput([cap2, cap1])); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -652,7 +652,8 @@ contract('Kernel with entry procedure', function (accounts) { it('E() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -666,7 +667,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx2 = await kernel.registerAnyProcedure(testProcName, deployedTestContract.address, beakerlib.Cap.toInput([cap1])); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -682,7 +682,8 @@ contract('Kernel with entry procedure', function (accounts) { it('E() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -697,7 +698,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx2 = await kernel.registerAnyProcedure(testProcName, deployedTestContract.address, beakerlib.Cap.toInput([cap1])); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -713,7 +713,8 @@ contract('Kernel with entry procedure', function (accounts) { it('E() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -728,7 +729,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx2 = await kernel.registerAnyProcedure(testProcName, deployedTestContract.address, beakerlib.Cap.toInput([cap2, cap1])); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -744,7 +744,8 @@ contract('Kernel with entry procedure', function (accounts) { it('E() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); @@ -759,7 +760,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx2 = await kernel.registerAnyProcedure(testProcName, deployedTestContract.address, beakerlib.Cap.toInput([cap1])); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -773,13 +773,12 @@ contract('Kernel with entry procedure', function (accounts) { }) }) describe('F() - successive calls single depth', function () { - const testProcName = "Adder"; - const testBytecode = Valid.Adder.bytecode; const functionSpec = "F()"; it('F() should succeed when given a general cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -799,8 +798,6 @@ contract('Kernel with entry procedure', function (accounts) { // await kernel.createProcedure("SysCallTestCall", Valid.SysCallTestCall.bytecode, beakerlib.Cap.toInput([cap2, cap1])); { - await testutils.installEntryProc(kernel); - // Procedure keys must occupay the first 24 bytes, so must be // padded const functionSelectorHash = web3.sha3(functionSpec).slice(2,10); @@ -808,7 +805,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx3 = await kernel.sendTransaction({data: inputData}); const valueXRaw = await web3.eth.call({to: kernel.address, data: inputData}); const valueX = web3.toBigNumber(valueXRaw); - assert.equal(valueX.toNumber(),8, `new value should be 8`); } const newValue2 = await kernel.testGetter.call(); @@ -822,7 +818,8 @@ contract('Kernel with entry procedure', function (accounts) { it('G() should succeed when given a general cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); diff --git a/test/withentryproc/syscalls/delete.js b/test/withentryproc/syscalls/delete.js index 399cc2b..3c4e775 100644 --- a/test/withentryproc/syscalls/delete.js +++ b/test/withentryproc/syscalls/delete.js @@ -28,7 +28,7 @@ const Invalid = { contract('Kernel with entry procedure', function (accounts) { describe('Delete capability', function () { - const entryProcName = "EntryProcedure"; + const entryProcName = "init"; describe('When given cap to delete a specific procedure Id', function () { // * Introduces Procedure A and Procedure B into the procedure table. @@ -47,15 +47,13 @@ contract('Kernel with entry procedure', function (accounts) { it('Delete procedure with matching id', async function() { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); - // Install Procedure A as the entry procedure const procAName = "ProcedureA"; const procBName = "ProcedureB"; @@ -113,14 +111,14 @@ contract('Kernel with entry procedure', function (accounts) { }) it('Fails to delete procedure if non-matching id', async function() { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -195,14 +193,14 @@ contract('Kernel with entry procedure', function (accounts) { it('Delete a procedure', async function () { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -288,7 +286,8 @@ contract('Kernel with entry procedure', function (accounts) { }) it('Delete itself', async function () { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); @@ -297,8 +296,7 @@ contract('Kernel with entry procedure', function (accounts) { const proceduresRaw = await kernel.listProcedures.call(); const procedures = proceduresRaw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); } - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -384,14 +382,14 @@ contract('Kernel with entry procedure', function (accounts) { }) it('Fail to delete the entry procedure', async function () { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -477,14 +475,14 @@ contract('Kernel with entry procedure', function (accounts) { it('Fail to delete non-existent procedure', async function () { const nonExistentName = "NonExistant"; // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -590,14 +588,14 @@ contract('Kernel with entry procedure', function (accounts) { it('Fail to delete a procedure', async function () { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -683,14 +681,14 @@ contract('Kernel with entry procedure', function (accounts) { }) it('Fail to delete itself', async function () { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); + // Install Procedure A as the entry procedure const procAName = "ProcedureA"; @@ -776,15 +774,13 @@ contract('Kernel with entry procedure', function (accounts) { }) it('Fail to delete the entry procedure', async function () { // Deploy the kernel - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); // Save the initial state of the procedure table const procedures1Raw = await kernel.listProcedures.call(); const procedures1 = procedures1Raw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - // Install the default entry procedure - await testutils.installEntryProc(kernel); - // Install Procedure A as the entry procedure const procAName = "ProcedureA"; const capArrayEntryProc = beakerlib.Cap.toInput([ diff --git a/test/withentryproc/syscalls/entry.js b/test/withentryproc/syscalls/entry.js index e82379a..993cee5 100644 --- a/test/withentryproc/syscalls/entry.js +++ b/test/withentryproc/syscalls/entry.js @@ -22,7 +22,8 @@ contract('Kernel with entry procedure', function (accounts) { const testContract = TestWrite; it('A() should succeed when given cap and correct procedure Id', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.SetEntryCap(); @@ -63,7 +64,8 @@ contract('Kernel with entry procedure', function (accounts) { }) it('A() should fail when given cap but invalid procedure Id', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.SetEntryCap(); diff --git a/test/withentryproc/syscalls/log.js b/test/withentryproc/syscalls/log.js index 3523d31..a3bd0ab 100644 --- a/test/withentryproc/syscalls/log.js +++ b/test/withentryproc/syscalls/log.js @@ -29,7 +29,8 @@ contract('Kernel with entry procedure', function (accounts) { describe('A() No topics', function () { const functionSpec = "A()"; it('A() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([]); @@ -39,7 +40,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx1 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -52,7 +52,8 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('A() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const capArray = beakerlib.Cap.toInput([cap1]); @@ -61,7 +62,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx0 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -77,7 +77,8 @@ contract('Kernel with entry procedure', function (accounts) { }) it('A() should fail when cap requires more topics', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap(["0xaabb"]); @@ -87,7 +88,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx0 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -109,7 +109,8 @@ contract('Kernel with entry procedure', function (accounts) { // must be the same const topic = "0xabcd"; it('B() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic]); @@ -119,7 +120,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx1 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -134,7 +134,8 @@ contract('Kernel with entry procedure', function (accounts) { }) it('B() should fail when cap has incorrect topic', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic+"1"]); @@ -144,7 +145,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx1 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -160,14 +160,14 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('B() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); const tx = await kernel.registerProcedure(procName, deployedContract.address, []); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -183,7 +183,8 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('B() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); @@ -193,7 +194,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -216,7 +216,8 @@ contract('Kernel with entry procedure', function (accounts) { const topic0 = "0xabcd"; const topic1 = "0xbeef"; it('C() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic0, topic1]); @@ -226,7 +227,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx1 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -241,14 +241,14 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('C() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); const tx = await kernel.registerProcedure(procName, deployedContract.address, []); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -264,14 +264,14 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('C() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, [3, 0x7, 0x8001, 0x0]); const tx = await kernel.registerProcedure(procName, deployedContract.address, [3, 0x7, 0x8001, 0x0]); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -295,7 +295,8 @@ contract('Kernel with entry procedure', function (accounts) { const topic1 = "0xbeef"; const topic2 = "0xcafe"; it('D() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic0, topic1, topic2]); @@ -306,7 +307,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -324,14 +324,14 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('D() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); const tx = await kernel.registerProcedure(procName, deployedContract.address, []); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -347,7 +347,8 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('D() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); @@ -357,7 +358,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -381,7 +381,8 @@ contract('Kernel with entry procedure', function (accounts) { const topic2 = "0xcafe"; const topic3 = "0x4545"; it('E() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic0, topic1, topic2, topic3]); @@ -391,7 +392,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx1 = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -409,13 +409,13 @@ contract('Kernel with entry procedure', function (accounts) { }) it('E() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); const tx = await kernel.registerProcedure(procName, deployedContract.address, []); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -431,7 +431,8 @@ contract('Kernel with entry procedure', function (accounts) { } }) it('E() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); @@ -441,7 +442,6 @@ contract('Kernel with entry procedure', function (accounts) { const tx = await kernel.registerProcedure(procName, deployedContract.address, capArray); { - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded diff --git a/test/withentryproc/syscalls/register.js b/test/withentryproc/syscalls/register.js index aa152b9..3e5e0f9 100644 --- a/test/withentryproc/syscalls/register.js +++ b/test/withentryproc/syscalls/register.js @@ -1,11 +1,11 @@ const debug = require('debug') const assert = require('assert') -const Kernel = artifacts.require('./TestKernel.sol') const abi = require('ethereumjs-abi') const beakerlib = require("../../../beakerlib"); const testutils = require("../../testutils.js"); +const BasicEntryProcedure = artifacts.require('BasicEntryProcedure.sol'); // Valid Contracts const Valid = { @@ -407,7 +407,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = true; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -449,7 +449,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = true; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -491,7 +491,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = true; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -533,7 +533,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = true; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -575,7 +575,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = false; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -614,7 +614,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = false; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -653,7 +653,7 @@ contract('Kernel with entry procedure', function () { const shouldSucceed = false; // Deploy the test kernel - const kernel = await deployKernelTest(); + const kernel = await testutils.deployTestKernel(); // Register Procedure A await regProcDirectTest(kernel, procAName, procAContract, procACaps); @@ -937,30 +937,6 @@ async function testCallType(ThisCap, capIndex) { }); } -// Deploy a kernel and install the example entry procedure -async function deployKernelTest() { - const kernel = await Kernel.new(); - const procedures1Raw = await kernel.listProcedures.call(); - const procedures1 = procedures1Raw.map(web3.toAscii) - .map(s => s.replace(/\0.*$/, '')); - assert(procedures1.length == 0, - "The kernel should initially have no procedures"); - const [regEPTX, setEPTX] = await testutils.installEntryProc(kernel); - - const procedures2Raw = await kernel.listProcedures.call(); - const procedures2 = procedures2Raw.map(web3.toAscii) - .map(s => s.replace(/\0.*$/, '')); - // Check that the entry procedure was correctly installed. - assert(procedures2.includes("EntryProcedure"), - "The kernel should have an entry procedure registered"); - let entryProcedureNameRaw = await kernel.getEntryProcedure.call(); - let entryProcedureName = web3.toAscii(web3.toHex(entryProcedureNameRaw)) - .replace(/\0.*$/, ''); - assert.strictEqual(entryProcedureName, - "EntryProcedure", "The entry procedure should be correctly set"); - return kernel; -} - async function regProcDirectTest(kernel, procName, procContract, procCaps) { // Check that proc is not already installed const procedures1Raw = await kernel.listProcedures.call(); @@ -1135,27 +1111,8 @@ async function delProcTest(kernel, procAName, procBName, shouldSucceed) { // attempt to register procB with. async function stdTest(procAName, procAContract, procACaps, procBName, procBContract, procBCaps, shouldSucceed) { - const kernel = await Kernel.new(); - const functionSpec = "B(bytes24,address,uint256[])"; - const procedures1Raw = await kernel.listProcedures.call(); - const procedures1 = procedures1Raw.map(web3.toAscii) - .map(s => s.replace(/\0.*$/, '')); - assert(procedures1.length == 0, - "The kernel should initially have no procedures"); - const [regEPTX, setEPTX] = await testutils.installEntryProc(kernel); - - const procedures2Raw = await kernel.listProcedures.call(); - const procedures2 = procedures2Raw.map(web3.toAscii) - .map(s => s.replace(/\0.*$/, '')); - // Check that the entry procedure was correctly installed. - assert(procedures2.includes("EntryProcedure"), - "The kernel should have an entry procedure registered"); - let entryProcedureNameRaw = await kernel.getEntryProcedure.call(); - let entryProcedureName = web3.toAscii(web3.toHex(entryProcedureNameRaw)) - .replace(/\0.*$/, ''); - assert.strictEqual(entryProcedureName, - "EntryProcedure", "The entry procedure should be correctly set"); + const kernel = await testutils.deployTestKernel(); const deployedContractA = await testutils.deployedTrimmed(procAContract); // This is the procedure that will do the registering @@ -1168,14 +1125,15 @@ async function stdTest(procAName, procAContract, procACaps, .map(s => s.replace(/\0.*$/, '')); assert(procedures3.includes(procAName), "ProcA should be registered"); + const functionSpec = "B(bytes24,address,uint256[])"; { // Test that procA returns the correct testNum const functionSelectorHash = web3.sha3("testNum()").slice(2,10); const inputData = web3.fromAscii(procAName.padEnd(24,"\0")) + functionSelectorHash; - const tx3 = await kernel.sendTransaction({data: inputData}); const valueXRaw = await web3.eth.call({to: kernel.address, data: inputData}); + const tx3 = await kernel.sendTransaction({data: inputData}); const valueX = web3.toBigNumber(valueXRaw); // we execute a test function to ensure the procedure is // functioning properly diff --git a/test/withentryproc/syscalls/write.js b/test/withentryproc/syscalls/write.js index 818c910..e7a02d2 100644 --- a/test/withentryproc/syscalls/write.js +++ b/test/withentryproc/syscalls/write.js @@ -25,8 +25,8 @@ const Invalid = { contract('Kernel with entry procedure', function (accounts) { describe('Write SysCall Procedure', function () { it('S() should succeed when given cap', async function () { - const kernel = await Kernel.new(); - const factory = await Factory.new(); + + const kernel = await testutils.deployTestKernel(); const capArraySysCallTest = beakerlib.Cap.toInput([ new beakerlib.WriteCap(0x8500,2), @@ -40,7 +40,6 @@ contract('Kernel with entry procedure', function (accounts) { const newValue1 = await kernel.testGetter.call(); assert.equal(newValue1.toNumber(), 3, "The value should be 3 before the execution"); - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -68,7 +67,8 @@ contract('Kernel with entry procedure', function (accounts) { }) it('S() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const SysCallTestWrite = await testutils.deployedTrimmed(Valid.SysCallTestWrite); const simpleTest = await testutils.deployedTrimmed(Valid.Multiply); @@ -78,7 +78,6 @@ contract('Kernel with entry procedure', function (accounts) { const newValue1 = await kernel.testGetter.call(); assert.equal(newValue1.toNumber(), 3, "The value should be 3 before the execution"); - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded @@ -105,7 +104,8 @@ contract('Kernel with entry procedure', function (accounts) { assert.equal(newValue4.toNumber(), 3, "The value should still be 3 after the execution"); }) it('S() should fail when trying to write to an address below its cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const capArraySysCallTest = beakerlib.Cap.toInput([ new beakerlib.WriteCap(0x8500,2), @@ -119,7 +119,6 @@ contract('Kernel with entry procedure', function (accounts) { const newValue1 = await kernel.testGetter.call(); assert.equal(newValue1.toNumber(), 3, "The value should be 3 before the execution"); - await testutils.installEntryProc(kernel); // Procedure keys must occupay the first 24 bytes, so must be // padded diff --git a/test/withoutentryproc/procedures.js b/test/withoutentryproc/procedures.js index c933998..ed20006 100644 --- a/test/withoutentryproc/procedures.js +++ b/test/withoutentryproc/procedures.js @@ -37,23 +37,24 @@ const testAccount = 0; contract('Kernel without entry procedure', function (accounts) { describe('.listProcedures()', function () { it('should return nothing if zero procedures', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); let procedures = await kernel.listProcedures.call(); - assert.equal(procedures.length, 0); + assert.equal(procedures.length, 1); }) it('should return existing procedure keys', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); const testAdder = await testutils.deployedTrimmed(Valid.Adder); let [err, address] = await kernel.registerProcedure.call('TestAdder', testAdder.address, []); let tx1 = await kernel.registerProcedure('TestAdder', testAdder.address, []); let procedures = await kernel.listProcedures.call(); - assert.equal(procedures.length, 1); + assert.equal(procedures.length, 2); }); it('should return a list of procedures which can be retrieved', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const speccedProcedures = [ ["TestAdder", Valid.Adder], ["TestDivider", Valid.Divide], @@ -69,14 +70,15 @@ contract('Kernel without entry procedure', function (accounts) { const procedures = proceduresRaw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); // Test that the number of procedures stored is the same as the - // number of procedures created - assert.equal(procedures.length, speccedProcedures.length); + // number of procedures created. The +1 accounts for the entry proc + assert.equal(procedures.length, speccedProcedures.length+1); // Cycle through each of the listed procedures - for (const i in procedures) { - // Test that the order and indexing of procedures is the same - assert.equal(speccedProcedures[i][0], procedures[i]) + for (let i = 0; i < (procedures.length - 1); i++) { + // Test that the order and indexing of procedures is the same. + // We skip procedure 0, as that is the entry proc. + assert.equal(speccedProcedures[i][0], procedures[i+1]) // Retrieve the listed procedure adress - const address = await kernel.getProcedureAddress.call(procedures[i]); + const address = await kernel.getProcedureAddress.call(procedures[i+1]); // Check the address is correct assert(web3.isAddress(address), `Procedure Address (${address}) is a real address`); assert(!isNullAddress(address), `Procedure Address (${address}) is not null`); @@ -88,7 +90,7 @@ contract('Kernel without entry procedure', function (accounts) { }) describe('.getProcedureAddress()', function () { it('should return a non-zero address iff procedure exists', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); // Create "TestAdder" // Find the address (ephemerally) @@ -108,7 +110,7 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(creationAddress, address); }); it('should return a zero address iff procedure does not exist', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); // No procedures exist yet (nor does "TestAdder") let address = await kernel.getProcedureAddress.call('TestAdder'); assert(web3.isAddress(address), `Procedure Address (${address}) is a real address`) @@ -118,7 +120,7 @@ contract('Kernel without entry procedure', function (accounts) { describe('.registerProcedure()', function () { it('should create valid procedure', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); const procedureName = "TestAdder"; const testAdder = await testutils.deployedTrimmed(Valid.Adder); let [err, address] = await kernel.registerProcedure.call(procedureName, testAdder.address, []); @@ -142,7 +144,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(testutils.trimSwarm(Valid.Adder.deployedBytecode), code); }); it('should create valid procedure (max key length)', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const name = "start1234567890123456end"; assert.equal(name.length, 24); const testAdder = await testutils.deployedTrimmed(Valid.Adder); @@ -167,7 +170,8 @@ contract('Kernel without entry procedure', function (accounts) { }); it('should create 2 valid procedures', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const proceduresRaw1 = await kernel.listProcedures.call(); const name = "start1234567890123456end"; @@ -210,7 +214,7 @@ contract('Kernel without entry procedure', function (accounts) { describe('should reject invalid key', function () { it('zero length', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); const testAdder = await testutils.deployedTrimmed(Valid.Adder); let [err, creationAddress] = await kernel.registerProcedure.call('', testAdder.address, []); @@ -220,7 +224,9 @@ contract('Kernel without entry procedure', function (accounts) { const proceduresRaw = await kernel.listProcedures.call(); const procedures = proceduresRaw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - assert.equal(procedures.length, 0); + // There should be a single procedure: the initial entry + // procedure. + assert.equal(procedures.length, 1); assert(!procedures.includes('')) const address = await kernel.getProcedureAddress.call(''); @@ -229,7 +235,8 @@ contract('Kernel without entry procedure', function (accounts) { }); it('duplicate procedure key', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const name = "TestAdder"; const testAdder = await testutils.deployedTrimmed(Valid.Adder); // This is the first time the procedure is added @@ -244,7 +251,9 @@ contract('Kernel without entry procedure', function (accounts) { const proceduresRaw = await kernel.listProcedures.call(); const procedures = proceduresRaw.map(web3.toAscii).map(s => s.replace(/\0.*$/, '')); - assert.equal(procedures.length, 1); + // There should be two procedures, the intial entry procedure, + // and teh procedure we first registered. + assert.equal(procedures.length, 2); const address = await kernel.getProcedureAddress.call(name); assert.equal(address, address1); @@ -261,12 +270,14 @@ contract('Kernel without entry procedure', function (accounts) { describe('.deleteProcedure()', function () { it('should return error if procedure key does not exist(3)', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const [err, deleteAddress] = await kernel.deleteProcedure.call('test'); assert.equal(err, 2); }); it('should return deleted procedure address if procedure key is valid', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const testAdder = await testutils.deployedTrimmed(Valid.Adder); const [err1, address] = await kernel.registerProcedure.call("test", testAdder.address, []); assert.equal(err1, 0); @@ -287,7 +298,8 @@ contract('Kernel without entry procedure', function (accounts) { }); it('should remove the procedure from the list on deletion', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const procedureName = "test"; const testAdder = await testutils.deployedTrimmed(Valid.Adder); @@ -321,7 +333,8 @@ contract('Kernel without entry procedure', function (accounts) { }) it('should remove the procedure from the list on deletion (multiple)', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const procedureName = "test"; const testAdder = await testutils.deployedTrimmed(Valid.Adder); @@ -369,7 +382,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('should not have side-effects', function() { it('removing then registering a new proc with same name + capabilities', async function() { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const table0 = await kernel.returnRawProcedureTable.call() const cap1 = new beakerlib.LogCap([]); @@ -402,7 +416,8 @@ contract('Kernel without entry procedure', function (accounts) { it('removing then registering a superset with same name', async function() { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const table_empty = await kernel.returnRawProcedureTable.call() const cap1 = new beakerlib.LogCap([]); @@ -439,7 +454,8 @@ contract('Kernel without entry procedure', function (accounts) { // TODO: this is not currently functional it.skip('should destroy the procedures contract on deletion', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const testAdder = await testutils.deployedTrimmed(Valid.Adder); const [err1, address] = await kernel.registerProcedure.call("test", testAdder.address, []); assert.equal(err1, 0); @@ -467,7 +483,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('should reject invalid key', function () { it('zero length (1)', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const [err, deleteAddress] = await kernel.deleteProcedure.call(''); assert.equal(err, 1); @@ -477,7 +494,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('.executeProcedure(bytes24 key, bytes payload)', function () { it('should return error if procedure key does not exist(3)', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const procName = "test"; const functionSpec = "executeProcedure(bytes24,string,bytes)" @@ -498,7 +516,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('Simple Procedure', function () { it('X() should fail', async function () { // This now longer fails as we included a fallback function - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const procName = "Simple"; const testSimple = await testutils.deployedTrimmed(Valid.Simple); const [, address] = await kernel.registerAnyProcedure.call(procName, testSimple.address, []); @@ -524,7 +543,8 @@ contract('Kernel without entry procedure', function (accounts) { }) it('A() should succeed', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const procName = "Simple"; const testSimple = await testutils.deployedTrimmed(Valid.Simple); const [, address] = await kernel.registerAnyProcedure.call(procName, testSimple.address, []); @@ -550,7 +570,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should fail without correctly specifying arguments', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const procName = "Simple"; const testSimple = await testutils.deployedTrimmed(Valid.Simple); const [, address] = await kernel.registerAnyProcedure.call(procName, testSimple.address, []); @@ -577,7 +598,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should fail when using type synonyms such as uint, which cant be used in function selectors', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const procName = "Simple"; const testSimple = await testutils.deployedTrimmed(Valid.Simple); const [, address] = await kernel.registerAnyProcedure.call(procName, testSimple.address, []); @@ -602,7 +624,8 @@ contract('Kernel without entry procedure', function (accounts) { }) it('C(uint256) should succeed passing arguments', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const procName = "Simple"; const testSimple = await testutils.deployedTrimmed(Valid.Simple); const [, address] = await kernel.registerAnyProcedure.call(procName, testSimple.address, []); @@ -630,7 +653,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('Discover Procedure Table', function () { it('should print a procedure table', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.WriteCap(0x8000,0); @@ -669,7 +693,8 @@ contract('Kernel without entry procedure', function (accounts) { describe.skip('Entry Procedure', function () { it('should return the entry procedure address', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const procedureName = "Entry"; const SysCallTestWrite = await testutils.deployedTrimmed(Valid.SysCallTestWrite); const [a, address] = await kernel.registerProcedure.call(procedureName, SysCallTestWrite.address, [3, 0x7, 0x80, 0x0]); @@ -695,7 +720,8 @@ contract('Kernel without entry procedure', function (accounts) { }) it('should return an error if key does not exist (3)', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const procName = "test"; const functionSpec = "executeProcedure(bytes24,string,bytes)" @@ -719,7 +745,7 @@ contract('Kernel without entry procedure', function (accounts) { describe('should return an error if procedure return error when', function () { it('receives invalid arguments') it('throws an error', async function () { - let kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); const testDivide = await testutils.deployedTrimmed(Valid.Divide); let [err, address] = await kernel.registerProcedure.call('TestDivide', testDivide.address, []); @@ -747,7 +773,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('should reject invalid key', function () { it('zero length (1)', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const procName = ""; const functionSpec = "executeProcedure(bytes24,string,bytes)" diff --git a/test/withoutentryproc/syscalls/call.js b/test/withoutentryproc/syscalls/call.js index b8dd9b7..075d7ba 100644 --- a/test/withoutentryproc/syscalls/call.js +++ b/test/withoutentryproc/syscalls/call.js @@ -42,7 +42,8 @@ contract('Kernel without entry procedure', function (accounts) { it('A() should succeed when given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -84,7 +85,8 @@ contract('Kernel without entry procedure', function (accounts) { it('A() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -111,7 +113,8 @@ contract('Kernel without entry procedure', function (accounts) { it('A() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -139,7 +142,8 @@ contract('Kernel without entry procedure', function (accounts) { it('A() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -167,7 +171,8 @@ contract('Kernel without entry procedure', function (accounts) { it('A() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -201,7 +206,8 @@ contract('Kernel without entry procedure', function (accounts) { it('B() should succeed when given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -229,7 +235,8 @@ contract('Kernel without entry procedure', function (accounts) { it('B() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -257,7 +264,8 @@ contract('Kernel without entry procedure', function (accounts) { it('B() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -285,7 +293,8 @@ contract('Kernel without entry procedure', function (accounts) { it('B() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -313,7 +322,8 @@ contract('Kernel without entry procedure', function (accounts) { it('B() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -347,7 +357,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should succeed when given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -375,7 +386,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -402,7 +414,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -430,7 +443,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -458,7 +472,8 @@ contract('Kernel without entry procedure', function (accounts) { it('C() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -492,7 +507,8 @@ contract('Kernel without entry procedure', function (accounts) { it('E() should succeed when given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -514,7 +530,8 @@ contract('Kernel without entry procedure', function (accounts) { it('E() should fail when not given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -535,7 +552,8 @@ contract('Kernel without entry procedure', function (accounts) { it('E() should fail when given the wrong cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -557,7 +575,8 @@ contract('Kernel without entry procedure', function (accounts) { it('E() should succeed with a more restricted cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -579,7 +598,8 @@ contract('Kernel without entry procedure', function (accounts) { it('E() should fail when the given cap is insufficient', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from 3 to 356. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -606,7 +626,8 @@ contract('Kernel without entry procedure', function (accounts) { it('F() should succeed when given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.WriteCap(0x8000,2); @@ -650,7 +671,8 @@ contract('Kernel without entry procedure', function (accounts) { it('G() should succeed when given cap', async function () { // This tests calls a test procedure which changes a storage // value in the kernel from x to x+1. - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8000,2); const cap2 = new beakerlib.LogCap([]); diff --git a/test/withoutentryproc/syscalls/log.js b/test/withoutentryproc/syscalls/log.js index 18756b7..26b5123 100644 --- a/test/withoutentryproc/syscalls/log.js +++ b/test/withoutentryproc/syscalls/log.js @@ -28,7 +28,8 @@ contract('Kernel without entry procedure', function (accounts) { describe('A() No topics', function () { const functionSpec = "A()"; it('A() should succeed when given "*" cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([]); @@ -45,7 +46,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx.receipt.logs[0].topics.length,0,"There should not be any topics"); }) it('A() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const capArray = beakerlib.Cap.toInput([cap1]); @@ -60,7 +62,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx1.receipt.logs.length, 0, "Nothing should be logged"); }) it('A() should fail when cap requires more topics', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap(["0xaabb"]); @@ -83,7 +86,8 @@ contract('Kernel without entry procedure', function (accounts) { // must be the same const topic = "0xabcd"; it('B() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic]); @@ -101,7 +105,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx.receipt.logs[0].topics[0],"0x"+topic.slice(2).padStart(64,0),"The topic should be correct"); }) it('B() should fail when cap has incorrect topic', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic+"1"]); @@ -117,7 +122,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx.receipt.logs.length, 0, "Nothing should be logged"); }) it('B() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); @@ -130,7 +136,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx1.receipt.logs.length, 0, "Nothing should be logged"); }) it('B() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); @@ -154,7 +161,8 @@ contract('Kernel without entry procedure', function (accounts) { const topic0 = "0xabcd"; const topic1 = "0xbeef"; it('C() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic0, topic1]); @@ -173,7 +181,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx.receipt.logs[0].topics[1],"0x"+topic1.slice(2).padStart(64,0),"The topic1 should be correct"); }) it('C() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); const tx = await kernel.registerProcedure(procName, deployedContract.address, []); @@ -185,7 +194,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx1.receipt.logs.length, 0, "Nothing should be logged"); }) it('C() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); @@ -209,7 +219,8 @@ contract('Kernel without entry procedure', function (accounts) { const topic1 = "0xbeef"; const topic2 = "0xcafe"; it('D() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic0, topic1, topic2]); @@ -229,7 +240,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx.receipt.logs[0].topics[2],"0x"+topic2.slice(2).padStart(64,0),"The topic1 should be correct"); }) it('D() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); @@ -242,7 +254,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx1.receipt.logs.length, 0, "Nothing should be logged"); }) it('D() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); @@ -267,7 +280,8 @@ contract('Kernel without entry procedure', function (accounts) { const topic2 = "0xcafe"; const topic3 = "0x4545"; it('E() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.LogCap([topic0, topic1, topic2, topic3]); @@ -288,7 +302,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx.receipt.logs[0].topics[3],"0x"+topic3.slice(2).padStart(64,0),"The topic1 should be correct"); }) it('E() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const deployedContract = await testutils.deployedTrimmed(contract); const [, address] = await kernel.registerProcedure.call(procName, deployedContract.address, []); @@ -301,7 +316,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(tx1.receipt.logs.length, 0, "Nothing should be logged"); }) it('E() should fail when trying to log to something outside its capability', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap = new beakerlib.LogCap(["0x8001", "0x0"]); const capArray = beakerlib.Cap.toInput([cap]); diff --git a/test/withoutentryproc/syscalls/write.js b/test/withoutentryproc/syscalls/write.js index 759b3e6..fa113f5 100644 --- a/test/withoutentryproc/syscalls/write.js +++ b/test/withoutentryproc/syscalls/write.js @@ -26,7 +26,8 @@ const SysCallResponse = beakerlib.SysCallResponse; contract('Kernel without entry procedure', function (accounts) { describe('Write SysCall Procedure', function () { it('S() should succeed when given cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const cap1 = new beakerlib.WriteCap(0x8500,2); const cap2 = new beakerlib.WriteCap(0x8000,0); @@ -54,7 +55,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(newValue3.toNumber(), 5, "The value should be 5 after the second execution"); }) it('S() should fail when not given cap', async function () { - const kernel = await Kernel.new(); + const kernel = await testutils.deployTestKernel(); + const SysCallTestWrite = await testutils.deployedTrimmed(Valid.SysCallTestWrite); const [, address] = await kernel.registerProcedure.call("SysCallTestWrite", SysCallTestWrite.address, []); const tx = await kernel.registerProcedure("SysCallTestWrite", SysCallTestWrite.address, []); @@ -75,7 +77,8 @@ contract('Kernel without entry procedure', function (accounts) { assert.equal(newValue3.toNumber(), 3, "The value should still be 3 before the second execution"); }) it('S() should fail when trying to write to an address below its cap', async function () { - const kernel = await Kernel.new(); + + const kernel = await testutils.deployTestKernel(); const SysCallTestWrite = await testutils.deployedTrimmed(Valid.SysCallTestWrite);