mirror of https://github.com/embarklabs/embark.git
Merge pull request #474 from embark-framework/features/test-revamp-multi
Revamp tests to use a cleaner syntax and be faster
This commit is contained in:
commit
3e3c0b82b2
|
@ -189,9 +189,6 @@ class Cmd {
|
|||
.description(__('run tests'))
|
||||
.action(function (file, options) {
|
||||
i18n.setOrDetectLocale(options.locale);
|
||||
embark.initConfig('development', {
|
||||
embarkConfig: 'embark.json', interceptLogs: false
|
||||
});
|
||||
embark.runTests(file);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -98,6 +98,10 @@ class ContractDeployer {
|
|||
return next();
|
||||
}
|
||||
|
||||
// TODO find a better way to do that
|
||||
if (process.env.isTest) {
|
||||
return self.deployContract(contract, next);
|
||||
}
|
||||
// TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract
|
||||
self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
|
||||
if (!trackedContract) {
|
||||
|
|
|
@ -14,7 +14,7 @@ function log(eventType, eventName) {
|
|||
//console.log(eventType, eventName);
|
||||
}
|
||||
|
||||
EventEmitter.prototype._maxListeners = 200;
|
||||
EventEmitter.prototype._maxListeners = 300;
|
||||
const _on = EventEmitter.prototype.on;
|
||||
const _setHandler = EventEmitter.prototype.setHandler;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ const supported_languages = ['en', 'pt', 'fr'];
|
|||
i18n.configure({
|
||||
locales: supported_languages,
|
||||
register: global,
|
||||
//updateFiles: false,
|
||||
updateFiles: false,
|
||||
directory: path.join(__dirname, 'locales')
|
||||
});
|
||||
|
||||
|
|
|
@ -126,9 +126,6 @@
|
|||
"Unable to start the blockchain process. Is Geth installed?": "Unable to start the blockchain process. Is Geth installed?",
|
||||
"Error while downloading the file": "Error while downloading the file",
|
||||
"Error while loading the content of ": "Error while loading the content of ",
|
||||
"IPFS node is offline": "IPFS node is offline",
|
||||
"IPFS node detected": "IPFS node detected",
|
||||
"Webserver is offline": "Webserver is offline",
|
||||
"Installing packages...": "Installing packages...",
|
||||
"Next steps:": "Next steps:",
|
||||
"open another console in the same directory and run": "open another console in the same directory and run",
|
||||
|
@ -152,6 +149,9 @@
|
|||
"Starting ipfs process": "Starting ipfs process",
|
||||
"ipfs process started": "ipfs process started",
|
||||
"Starting swarm process": "Starting swarm process",
|
||||
"unknown command": "unknown command",
|
||||
"Simulator not found; Please install it with \"%s\"": "Simulator not found; Please install it with \"%s\"",
|
||||
"IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc \"%s\"": "IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc \"%s\"",
|
||||
"swarm process started": "swarm process started",
|
||||
"Storage process for swarm ended before the end of this process. Code: 12": "Storage process for swarm ended before the end of this process. Code: 12",
|
||||
"Storage process for swarm ended before the end of this process. Code: 1": "Storage process for swarm ended before the end of this process. Code: 1",
|
||||
|
@ -162,4 +162,4 @@
|
|||
"Cannot start {{platform}} node on {{url}}.": "Cannot start {{platform}} node on {{url}}.",
|
||||
"Storage process for swarm ended before the end of this process. Code: 0": "Storage process for swarm ended before the end of this process. Code: 0",
|
||||
"error uploading to swarm": "error uploading to swarm"
|
||||
}
|
||||
}
|
||||
|
|
15
lib/index.js
15
lib/index.js
|
@ -216,13 +216,6 @@ class Embark {
|
|||
});
|
||||
}
|
||||
|
||||
initTests(options) {
|
||||
this.context = options.context || [constants.contexts.test];
|
||||
let Test = require('./tests/test.js');
|
||||
options.context = this.context;
|
||||
return new Test(options);
|
||||
}
|
||||
|
||||
graph(options) {
|
||||
this.context = options.context || [constants.contexts.graph];
|
||||
options.onlyCompile = true;
|
||||
|
@ -372,14 +365,6 @@ class Embark {
|
|||
let RunTests = require('./tests/run_tests.js');
|
||||
RunTests.run(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// temporary until next refactor
|
||||
Embark.initTests = function(options) {
|
||||
let Test = require('./tests/test.js');
|
||||
options.context = [constants.contexts.test];
|
||||
return new Test(options);
|
||||
};
|
||||
|
||||
module.exports = Embark;
|
||||
|
|
|
@ -51,7 +51,7 @@ process.on('message', function (msg) {
|
|||
|
||||
if (msg.action === 'compile') {
|
||||
solcProcess.compile(msg.jsonObj, (output) => {
|
||||
process.send({result: "compilation", output: output});
|
||||
process.send({result: "compilation-" + msg.id, output: output});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ let utils = require('../../utils/utils.js');
|
|||
let fs = require('../../core/fs.js');
|
||||
let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
||||
const ProcessLauncher = require('../../process/processLauncher');
|
||||
const uuid = require('uuid/v1');
|
||||
|
||||
class SolcW {
|
||||
|
||||
|
@ -49,11 +50,12 @@ class SolcW {
|
|||
}
|
||||
|
||||
compile(jsonObj, done) {
|
||||
this.solcProcess.once('result', 'compilation', (msg) => {
|
||||
const id = uuid();
|
||||
this.solcProcess.once('result', 'compilation-' + id, (msg) => {
|
||||
done(JSON.parse(msg.output));
|
||||
});
|
||||
|
||||
this.solcProcess.send({action: 'compile', jsonObj: jsonObj});
|
||||
this.solcProcess.send({action: 'compile', jsonObj: jsonObj, id});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,80 +1,96 @@
|
|||
const utils = require('../utils/utils.js');
|
||||
const async = require('async');
|
||||
const fs = require('fs-extra');
|
||||
const Mocha = require('mocha');
|
||||
const path = require('path');
|
||||
const Test = require('./test');
|
||||
|
||||
function getFilesFromDir(filePath, cb) {
|
||||
fs.readdir(filePath, (err, files) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
const testFiles = files.filter((file) => {
|
||||
// Only keep the .js files
|
||||
// TODO: make this a configuration in embark.json
|
||||
return file.substr(-3) === '.js';
|
||||
}).map((file) => {
|
||||
return path.join(filePath, file);
|
||||
});
|
||||
cb(null, testFiles);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run: function(filepath) {
|
||||
const Mocha = require('mocha'),
|
||||
fs = require('fs-extra'),
|
||||
path = require('path');
|
||||
|
||||
const mocha = new Mocha();
|
||||
|
||||
if (filepath) {
|
||||
if (filepath.substr(-1) === '/') {
|
||||
// Add each .js file to the mocha instance
|
||||
fs.readdirSync(filepath).filter(function(file){
|
||||
// Only keep the .js files
|
||||
// TODO: make this a configuration in embark.json
|
||||
return file.substr(-3) === '.js';
|
||||
}).forEach(function(file){
|
||||
mocha.addFile(
|
||||
path.join(filepath, file)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
mocha.addFile(filepath);
|
||||
}
|
||||
} else {
|
||||
var testDir = 'test/';
|
||||
|
||||
// Add each .js file to the mocha instance
|
||||
fs.readdirSync(testDir).filter(function(file){
|
||||
// Only keep the .js files
|
||||
// TODO: make this a configuration in embark.json
|
||||
return file.substr(-3) === '.js';
|
||||
}).forEach(function(file){
|
||||
mocha.addFile(
|
||||
path.join(testDir, file)
|
||||
);
|
||||
});
|
||||
run: function (filePath) {
|
||||
process.env.isTest = true;
|
||||
let failures = 0;
|
||||
if (!filePath) {
|
||||
filePath = 'test/';
|
||||
}
|
||||
|
||||
let Test = require('./test.js');
|
||||
async.waterfall([
|
||||
function setupGlobalNamespace(next) {
|
||||
// TODO put default config
|
||||
const test = new Test();
|
||||
global.embark = test;
|
||||
global.config = test.config.bind(test);
|
||||
|
||||
global.assert = require('assert');
|
||||
// TODO: this global here might not be necessary at all
|
||||
global.web3 = global.embark.web3;
|
||||
|
||||
let configOptions = {
|
||||
gasPrice: 1
|
||||
};
|
||||
global.config = function(config) {
|
||||
configOptions = utils.recursiveMerge(configOptions, config);
|
||||
};
|
||||
// TODO: check how to pass the options
|
||||
//global.EmbarkSpec = new Test(options);
|
||||
global.contract = function (describeName, callback) {
|
||||
return Mocha.describe(describeName, callback);
|
||||
};
|
||||
|
||||
// TODO: this global here might not be necessary at all
|
||||
global.EmbarkSpec = new Test({});
|
||||
global.web3 = global.EmbarkSpec.web3;
|
||||
console.info('Compiling contracts'.cyan);
|
||||
test.init(next);
|
||||
},
|
||||
function getFiles(next) {
|
||||
if (filePath.substr(-1) !== '/') {
|
||||
return next(null, [filePath]);
|
||||
}
|
||||
getFilesFromDir(filePath, (err, files) => {
|
||||
if (err) {
|
||||
console.error('Error while reading the directory');
|
||||
return next(err);
|
||||
}
|
||||
next(null, files);
|
||||
});
|
||||
},
|
||||
function executeForAllFiles(files, next) {
|
||||
async.eachLimit(files, 1, (file, eachCb) => {
|
||||
const mocha = new Mocha();
|
||||
mocha.addFile(file);
|
||||
|
||||
global.contract = function(describeName, callback) {
|
||||
return Mocha.describe(describeName, callback);
|
||||
};
|
||||
mocha.suite.timeout(0);
|
||||
mocha.suite.beforeEach('Wait for deploy', (done) => {
|
||||
global.embark.onReady(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
mocha.run(function(fails) {
|
||||
failures += fails;
|
||||
// Mocha prints the error already
|
||||
eachCb();
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
], (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
if (failures) {
|
||||
console.error(` > Total number of failures: ${failures}`.red.bold);
|
||||
} else {
|
||||
console.log(' > All tests passed'.green.bold);
|
||||
}
|
||||
|
||||
// Run the tests.
|
||||
let runner = mocha.run(function(failures) {
|
||||
// Clean contracts folder for next test run
|
||||
fs.remove('.embark/contracts', (_err) => {
|
||||
process.on('exit', function () {
|
||||
process.exit(failures); // exit with non-zero status if there were failures
|
||||
});
|
||||
process.exit();
|
||||
process.exit(failures);
|
||||
});
|
||||
});
|
||||
|
||||
runner.on('suite', function() {
|
||||
global.assert = require('assert');
|
||||
global.EmbarkSpec = new Test({simulatorOptions: configOptions});
|
||||
global.web3 = global.EmbarkSpec.web3;
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,116 +1,193 @@
|
|||
var async = require('async');
|
||||
//require("../utils/debug_util.js")(__filename, async);
|
||||
var Web3 = require('web3');
|
||||
var Engine = require('../core/engine.js');
|
||||
var TestLogger = require('./test_logger.js');
|
||||
const async = require('async');
|
||||
const Engine = require('../core/engine.js');
|
||||
const TestLogger = require('./test_logger.js');
|
||||
const Web3 = require('web3');
|
||||
const utils = require('../utils/utils');
|
||||
const constants = require('../constants');
|
||||
const Events = require('../core/events');
|
||||
const cloneDeep = require('clone-deep');
|
||||
|
||||
var getSimulator = function() {
|
||||
function getSimulator() {
|
||||
try {
|
||||
var sim = require('ethereumjs-testrpc');
|
||||
return sim;
|
||||
return require('ganache-cli');
|
||||
} catch (e) {
|
||||
const moreInfo = 'For more information see https://github.com/trufflesuite/ganache-cli';
|
||||
if (e.code === 'MODULE_NOT_FOUND') {
|
||||
console.log(__('Simulator not found; Please install it with "%s"', 'npm install ethereumjs-testrpc --save'));
|
||||
console.log(__('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "%s"', 'npm install ethereumjs-testrpc@2.0 --save'));
|
||||
console.log('For more information see https://github.com/ethereumjs/testrpc');
|
||||
// TODO: should throw exception instead
|
||||
return process.exit();
|
||||
console.error(__('Simulator not found; Please install it with "%s"', 'npm install ganache-cli --save'));
|
||||
console.error(moreInfo);
|
||||
throw e;
|
||||
}
|
||||
console.log("==============");
|
||||
console.log(__("Tried to load testrpc but an error occurred. This is a problem with testrpc"));
|
||||
console.log(__('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "%s". Alternatively install node 6.9.1 and the testrpc 3.0', 'npm install ethereumjs-testrpc@2.0 --save'));
|
||||
console.log("==============");
|
||||
console.error("==============");
|
||||
console.error(__("Tried to load Ganache CLI (testrpc), but an error occurred. This is a problem with Ganache CLI"));
|
||||
console.error(moreInfo);
|
||||
console.error("==============");
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var Test = function(options) {
|
||||
this.options = options || {};
|
||||
this.simOptions = this.options.simulatorOptions || {};
|
||||
class Test {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
this.simOptions = this.options.simulatorOptions || {};
|
||||
this.contracts = {};
|
||||
this.events = new Events();
|
||||
this.ready = true;
|
||||
this.builtContracts = {};
|
||||
|
||||
this.engine = new Engine({
|
||||
env: this.options.env || 'test',
|
||||
// TODO: confi will need to detect if this is a obj
|
||||
embarkConfig: this.options.embarkConfig || 'embark.json',
|
||||
interceptLogs: false
|
||||
});
|
||||
this.web3 = new Web3();
|
||||
if (this.simOptions.node) {
|
||||
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||
} else {
|
||||
this.sim = getSimulator();
|
||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||
}
|
||||
|
||||
this.engine.init({
|
||||
logger: new TestLogger({logLevel: 'debug'})
|
||||
});
|
||||
this.engine = new Engine({
|
||||
env: this.options.env || 'test',
|
||||
// TODO: config will need to detect if this is a obj
|
||||
embarkConfig: this.options.embarkConfig || 'embark.json',
|
||||
interceptLogs: false
|
||||
});
|
||||
|
||||
this.web3 = new Web3();
|
||||
|
||||
if (this.simOptions.node) {
|
||||
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||
} else {
|
||||
this.sim = getSimulator();
|
||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||
this.engine.init({
|
||||
logger: new TestLogger({logLevel: 'debug'})
|
||||
});
|
||||
|
||||
this.versions_default = this.engine.config.contractsConfig.versions;
|
||||
// Reset contract config to nothing to make sure we deploy only what we want
|
||||
this.engine.config.contractsConfig = {contracts: {}, versions: this.versions_default};
|
||||
|
||||
this.engine.startService("libraryManager");
|
||||
this.engine.startService("codeRunner");
|
||||
this.engine.startService("web3", {
|
||||
web3: this.web3
|
||||
});
|
||||
this.engine.startService("deployment", {
|
||||
trackContracts: false
|
||||
});
|
||||
this.engine.startService("codeGenerator");
|
||||
}
|
||||
};
|
||||
|
||||
Test.prototype.getAccounts = function(cb) {
|
||||
this.web3.eth.getAccounts(function(err, accounts) {
|
||||
cb(err, accounts);
|
||||
});
|
||||
};
|
||||
init(callback) {
|
||||
const self = this;
|
||||
this.engine.contractsManager.build(() => {
|
||||
self.builtContracts = cloneDeep(self.engine.contractsManager.contracts);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||
var self = this;
|
||||
|
||||
async.waterfall([
|
||||
function getConfig(callback) {
|
||||
let _versions_default = self.engine.config.contractsConfig.versions;
|
||||
self.engine.config.contractsConfig = {contracts: contractsConfig, versions: _versions_default};
|
||||
callback();
|
||||
onReady(callback) {
|
||||
if (this.ready) {
|
||||
return callback();
|
||||
}
|
||||
this.events.once('ready', () => {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
config(options, callback) {
|
||||
if (!callback) {
|
||||
callback = function () {
|
||||
};
|
||||
}
|
||||
if (!options.contracts) {
|
||||
throw new Error(__('No contracts specified in the options'));
|
||||
}
|
||||
this.options = utils.recursiveMerge(this.options, options);
|
||||
this.simOptions = this.options.simulatorOptions || {};
|
||||
this.ready = false;
|
||||
|
||||
// Reset contracts
|
||||
this.engine.contractsManager.contracts = cloneDeep(this.builtContracts);
|
||||
|
||||
this._deploy(options, (err, accounts) => {
|
||||
this.ready = true;
|
||||
this.events.emit('ready');
|
||||
if (err) {
|
||||
console.error(err.red);
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, accounts);
|
||||
});
|
||||
}
|
||||
|
||||
_deploy(config, callback) {
|
||||
const self = this;
|
||||
async.waterfall([
|
||||
function getConfig(next) {
|
||||
self.engine.config.contractsConfig = {contracts: config.contracts, versions: self.versions_default};
|
||||
self.engine.events.emit(constants.events.contractConfigChanged, self.engine.config.contractsConfig);
|
||||
next();
|
||||
},
|
||||
function startServices(callback) {
|
||||
//{abiType: 'contracts', embarkJS: false}
|
||||
self.engine.startService("libraryManager");
|
||||
self.engine.startService("codeRunner");
|
||||
self.engine.startService("web3", {
|
||||
web3: self.web3
|
||||
});
|
||||
self.engine.startService("deployment", {
|
||||
trackContracts: false
|
||||
});
|
||||
self.engine.startService("codeGenerator");
|
||||
callback();
|
||||
},
|
||||
function deploy(callback) {
|
||||
self.engine.events.on('code-generator-ready', function () {
|
||||
self.engine.events.request('code-contracts-vanila', function(vanillaABI) {
|
||||
callback(null, vanillaABI);
|
||||
});
|
||||
});
|
||||
|
||||
function deploy(next) {
|
||||
self.engine.deployManager.gasLimit = 6000000;
|
||||
self.engine.contractsManager.gasLimit = 6000000;
|
||||
self.engine.deployManager.fatalErrors = true;
|
||||
self.engine.deployManager.deployOnlyOnConfig = true;
|
||||
self.engine.events.request('deploy:contracts', function(err) {
|
||||
self.engine.events.request('deploy:contracts', next);
|
||||
},
|
||||
function getAccounts(next) {
|
||||
self.web3.eth.getAccounts(function (err, accounts) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return next(err);
|
||||
}
|
||||
self.accounts = accounts;
|
||||
self.web3.eth.defaultAccount = accounts[0];
|
||||
next();
|
||||
});
|
||||
},
|
||||
function createContractObject(next) {
|
||||
async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => {
|
||||
const contract = self.engine.contractsManager.contracts[contractName];
|
||||
if (!self.contracts[contractName]) {
|
||||
self.contracts[contractName] = {};
|
||||
}
|
||||
Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.deployedAddress,
|
||||
{from: self.web3.eth.defaultAccount, gas: 6000000}));
|
||||
eachCb();
|
||||
}, next);
|
||||
}
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
console.log(__('terminating due to error'));
|
||||
process.exit(1);
|
||||
}
|
||||
// this should be part of the waterfall and not just something done at the
|
||||
// end
|
||||
self.web3.eth.getAccounts(function(err, accounts) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
throw new Error(err);
|
||||
console.log(__('terminating due to error'));
|
||||
return callback(err);
|
||||
}
|
||||
self.web3.eth.defaultAccount = accounts[0];
|
||||
self.engine.events.request('runcode:eval', result);
|
||||
//cb();
|
||||
cb(accounts);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
require(module) {
|
||||
if (module.startsWith('Embark/contracts/')) {
|
||||
const contractName = module.substr(17);
|
||||
if (this.contracts[contractName]) {
|
||||
return this.contracts[contractName];
|
||||
}
|
||||
let contract = this.engine.contractsManager.contracts[contractName];
|
||||
if (!contract) {
|
||||
const contractNames = Object.keys(this.engine.contractsManager.contracts);
|
||||
// It is probably an instanceof
|
||||
contractNames.find(contrName => {
|
||||
// Find a contract with a similar name
|
||||
if (contractName.indexOf(contrName) > -1) {
|
||||
contract = this.engine.contractsManager.contracts[contrName];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// If still nothing, assign bogus one, we will redefine it anyway on deploy
|
||||
if (!contract) {
|
||||
console.warn(__('Could not recognize the contract name "%s"'));
|
||||
console.warn(__('If it is an instance of another contract, it will be reassigned on deploy'));
|
||||
console.warn(__('Otherwise, you can rename the contract to contain the parent contract in the name eg: Token2 for Token'));
|
||||
contract = this.engine.contractsManager.contracts[contractNames[0]];
|
||||
}
|
||||
}
|
||||
this.contracts[contractName] = new this.web3.eth.Contract(contract.abiDefinition, contract.address,
|
||||
{from: this.web3.eth.defaultAccount, gas: 6000000});
|
||||
return this.contracts[contractName];
|
||||
}
|
||||
throw new Error(__('Unknown module %s', module));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Test;
|
||||
|
|
|
@ -11,7 +11,7 @@ class TestLogger {
|
|||
|
||||
logFunction() {
|
||||
this.logs.push(arguments);
|
||||
//console.dir(arguments[0]);
|
||||
// console.log(...arguments);
|
||||
}
|
||||
|
||||
contractsState() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,6 +33,7 @@
|
|||
"bip39": "^2.5.0",
|
||||
"blessed": "^0.1.81",
|
||||
"chokidar": "^2.0.3",
|
||||
"clone-deep": "^4.0.0",
|
||||
"colors": "^1.1.2",
|
||||
"commander": "^2.15.1",
|
||||
"css-loader": "^0.28.11",
|
||||
|
@ -40,12 +41,12 @@
|
|||
"ejs": "^2.5.8",
|
||||
"eth-ens-namehash": "^2.0.8",
|
||||
"eth-lib": "^0.2.8",
|
||||
"ethereumjs-testrpc": "^6.0.3",
|
||||
"ethereumjs-wallet": "^0.6.0",
|
||||
"file-loader": "^1.1.5",
|
||||
"finalhandler": "^1.1.1",
|
||||
"follow-redirects": "^1.2.4",
|
||||
"fs-extra": "^2.0.0",
|
||||
"ganache-cli": "^6.1.0",
|
||||
"globule": "^1.1.0",
|
||||
"hard-source-webpack-plugin": "^0.6.6",
|
||||
"http-shutdown": "^1.2.0",
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const AnotherStorage = embark.require('Embark/contracts/AnotherStorage');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("AnotherStorage", function() {
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
var contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("set SimpleStorage address", async function() {
|
||||
let result = await AnotherStorage.methods.simpleStorageAddress().call();
|
||||
assert.equal(result.toString(), SimpleStorage.options.address);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,37 +1,42 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const SomeContract = embark.require('Embark/contracts/SomeContract');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
const MyToken2 = embark.require('Embark/contracts/MyToken2');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"Token": {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
"MyToken2": {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("SomeContract", function() {
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
var contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"Token": {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
"MyToken2": {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("set MyToken2 address", async function() {
|
||||
let address = await SomeContract.methods.addr_1().call();
|
||||
assert.equal(address, MyToken2.options.address);
|
||||
assert.strictEqual(address, MyToken2.options.address);
|
||||
});
|
||||
|
||||
it("set SimpleStorage address", async function() {
|
||||
let address = await SomeContract.methods.addr_2().call();
|
||||
assert.equal(address, SimpleStorage.options.address);
|
||||
assert.strictEqual(address, SimpleStorage.options.address);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const Test2 = embark.require('Embark/contracts/Test2');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"Test2": {
|
||||
},
|
||||
"ZAMyLib": {
|
||||
},
|
||||
"ZAMyLib2": {
|
||||
"deploy": true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("Test", function() {
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
var contractsConfig = {
|
||||
"Test2": {
|
||||
},
|
||||
"ZAMyLib": {
|
||||
},
|
||||
"ZAMyLib2": {
|
||||
"deploy": true
|
||||
}
|
||||
};
|
||||
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("should call library correctly", async function() {
|
||||
let result = await Test2.methods.testAdd().call();
|
||||
assert.equal(result, 3);
|
||||
assert.strictEqual(parseInt(result, 10), 3);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,31 +1,26 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
|
||||
contract("SimpleStorage", function() {
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("SimpleStorage", function () {
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
|
||||
//config({
|
||||
// node: "http://localhost:8545"
|
||||
//});
|
||||
|
||||
var contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("should set constructor value", async function() {
|
||||
it("should set constructor value", async function () {
|
||||
let result = await SimpleStorage.methods.storedData().call();
|
||||
assert.equal(result, 100);
|
||||
assert.strictEqual(parseInt(result, 10), 100);
|
||||
});
|
||||
|
||||
it("set storage value", async function() {
|
||||
it("set storage value", async function () {
|
||||
await SimpleStorage.methods.set(150).send();
|
||||
let result = await SimpleStorage.methods.get().call();
|
||||
assert.equal(result, 499650);
|
||||
assert.strictEqual(parseInt(result, 10), 499650);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,87 +1,82 @@
|
|||
/*global describe, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const Token = embark.require('Embark/contracts/Token');
|
||||
const MyToken = embark.require('Embark/contracts/MyToken');
|
||||
const MyToken2 = embark.require('Embark/contracts/MyToken2');
|
||||
const AlreadyDeployedToken = embark.require('Embark/contracts/AlreadyDeployedToken');
|
||||
const Test = embark.require('Embark/contracts/Test');
|
||||
|
||||
describe("Token", function() {
|
||||
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
|
||||
//config({
|
||||
// node: "http://localhost:8545"
|
||||
//});
|
||||
|
||||
var contractsConfig = {
|
||||
"ZAMyLib": {
|
||||
},
|
||||
"Token": {
|
||||
},
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
},
|
||||
"Token": {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
"MyToken": {
|
||||
instanceOf: "Token"
|
||||
},
|
||||
"MyToken2": {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
"AlreadyDeployedToken": {
|
||||
"address": "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE",
|
||||
instanceOf: "Token"
|
||||
},
|
||||
"Test": {
|
||||
onDeploy: [
|
||||
"Test.methods.changeAddress('$MyToken').send()"
|
||||
]
|
||||
},
|
||||
"ContractArgs": {
|
||||
"args": {
|
||||
"initialValue": 123,
|
||||
"_addresses": ["$MyToken2", "$SimpleStorage"]
|
||||
}
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
config({
|
||||
contracts: {
|
||||
ZAMyLib: {},
|
||||
SimpleStorage: {
|
||||
args: [100]
|
||||
},
|
||||
AnotherStorage: {
|
||||
args: ["$SimpleStorage"]
|
||||
},
|
||||
Token: {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
MyToken: {
|
||||
instanceOf: "Token"
|
||||
},
|
||||
MyToken2: {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
AlreadyDeployedToken: {
|
||||
address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE",
|
||||
instanceOf: "Token"
|
||||
},
|
||||
Test: {
|
||||
onDeploy: ["Test.methods.changeAddress('$MyToken').send()"]
|
||||
},
|
||||
ContractArgs: {
|
||||
args: {
|
||||
initialValue: 123,
|
||||
_addresses: ["$MyToken2", "$SimpleStorage"]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("not deploy Token", function() {
|
||||
assert.equal(Token.address, "");
|
||||
});
|
||||
|
||||
it("not deploy MyToken and MyToken2", function() {
|
||||
assert.notEqual(MyToken.address, "");
|
||||
assert.notEqual(MyToken2.address, "");
|
||||
});
|
||||
|
||||
it("set MyToken Balance correctly", async function() {
|
||||
let result = await MyToken.methods._supply().call();
|
||||
assert.equal(result, 1000);
|
||||
});
|
||||
|
||||
it("set MyToken2 Balance correctly", async function() {
|
||||
let result = await MyToken2.methods._supply().call();
|
||||
assert.equal(result, 2000);
|
||||
});
|
||||
|
||||
it("get right address", function() {
|
||||
assert.equal(AlreadyDeployedToken.address, "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
|
||||
});
|
||||
|
||||
it("should use onDeploy", async function() {
|
||||
let result = await Test.methods.addr().call();
|
||||
assert.equal(result, MyToken.address)
|
||||
});
|
||||
|
||||
},
|
||||
SomeContract: {
|
||||
args: [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe("Token", function () {
|
||||
this.timeout(0);
|
||||
|
||||
it("not deploy Token", function () {
|
||||
assert.strictEqual(Token.address, undefined);
|
||||
});
|
||||
|
||||
it("should deploy MyToken and MyToken2", function () {
|
||||
assert.ok(MyToken.options.address);
|
||||
assert.ok(MyToken2.options.address);
|
||||
});
|
||||
|
||||
it("set MyToken Balance correctly", async function () {
|
||||
let result = await MyToken.methods._supply().call();
|
||||
assert.strictEqual(parseInt(result, 10), 1000);
|
||||
});
|
||||
|
||||
it("set MyToken2 Balance correctly", async function () {
|
||||
let result = await MyToken2.methods._supply().call();
|
||||
assert.strictEqual(parseInt(result, 10), 2000);
|
||||
});
|
||||
|
||||
it("get right address", function () {
|
||||
assert.strictEqual(AlreadyDeployedToken.options.address.toLowerCase(),
|
||||
"0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE".toLowerCase());
|
||||
});
|
||||
|
||||
it("should use onDeploy", async function () {
|
||||
let result = await Test.methods.addr().call();
|
||||
assert.strictEqual(result, MyToken.options.address);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
"dom-helpers": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz",
|
||||
"integrity": "sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg=="
|
||||
"integrity": "sha1-/BpOFf/fYN3eA6SAqcD+zoId1KY="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "4.0.0",
|
||||
|
@ -229,7 +229,7 @@
|
|||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
|
||||
"integrity": "sha1-mA9vcthSEaU0fGsrwYxbhMPrR+8=",
|
||||
"requires": {
|
||||
"encoding": "0.1.12",
|
||||
"is-stream": "1.1.0"
|
||||
|
@ -252,7 +252,7 @@
|
|||
"promise": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
|
||||
"integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
|
||||
"integrity": "sha1-BktyYCsY+Q8pGSuLG8QY/9Hr078=",
|
||||
"requires": {
|
||||
"asap": "2.0.6"
|
||||
}
|
||||
|
@ -289,7 +289,7 @@
|
|||
"react-bootstrap": {
|
||||
"version": "0.32.1",
|
||||
"resolved": "https://registry.npmjs.org/react-bootstrap/-/react-bootstrap-0.32.1.tgz",
|
||||
"integrity": "sha512-RbfzKUbsukWsToWqGHfCCyMFq9QQI0TznutdyxyJw6dih2NvIne25Mrssg8LZsprqtPpyQi8bN0L0Fx3fUsL8Q==",
|
||||
"integrity": "sha1-YGJMG0ijnXc+9szmQhpPM+zBZrs=",
|
||||
"requires": {
|
||||
"babel-runtime": "6.26.0",
|
||||
"classnames": "2.2.5",
|
||||
|
@ -319,7 +319,7 @@
|
|||
"react-overlays": {
|
||||
"version": "0.8.3",
|
||||
"resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-0.8.3.tgz",
|
||||
"integrity": "sha512-h6GT3jgy90PgctleP39Yu3eK1v9vaJAW73GOA/UbN9dJ7aAN4BTZD6793eI1D5U+ukMk17qiqN/wl3diK1Z5LA==",
|
||||
"integrity": "sha1-+tZe6lskMBzKGSoWn13dsLINOsU=",
|
||||
"requires": {
|
||||
"classnames": "2.2.5",
|
||||
"dom-helpers": "3.3.1",
|
||||
|
@ -353,7 +353,7 @@
|
|||
"regenerator-runtime": {
|
||||
"version": "0.11.1",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
|
||||
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg=="
|
||||
"integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk="
|
||||
},
|
||||
"setimmediate": {
|
||||
"version": "1.0.5",
|
||||
|
@ -412,7 +412,7 @@
|
|||
"zeppelin-solidity": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz",
|
||||
"integrity": "sha512-7Mxq6Y7EES0PSLrRF6v0EVYqBVRRo8hFrr7m3jEs69VbbQ5kpANzizeEdbP1/PWKSOmBOg208qP2vSA0FlzFLA==",
|
||||
"integrity": "sha1-BJ/N59rqn8hSEPjG25+M0auKhTo=",
|
||||
"requires": {
|
||||
"dotenv": "4.0.0",
|
||||
"ethjs-abi": "0.2.1"
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const AnotherStorage = embark.require('Embark/contracts/AnotherStorage');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("AnotherStorage", function() {
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
var contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("set SimpleStorage address", async function() {
|
||||
let result = await AnotherStorage.methods.simpleStorageAddress().call();
|
||||
assert.equal(result.toString(), SimpleStorage.options.address);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,37 +1,42 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const SomeContract = embark.require('Embark/contracts/SomeContract');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
const MyToken2 = embark.require('Embark/contracts/MyToken2');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"Token": {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
"MyToken2": {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("SomeContract", function() {
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
var contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"Token": {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
"MyToken2": {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("set MyToken2 address", async function() {
|
||||
let address = await SomeContract.methods.addr_1().call();
|
||||
assert.equal(address, MyToken2.options.address);
|
||||
assert.strictEqual(address, MyToken2.options.address);
|
||||
});
|
||||
|
||||
it("set SimpleStorage address", async function() {
|
||||
let address = await SomeContract.methods.addr_2().call();
|
||||
assert.equal(address, SimpleStorage.options.address);
|
||||
assert.strictEqual(address, SimpleStorage.options.address);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const Test2 = embark.require('Embark/contracts/Test2');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"Test2": {
|
||||
},
|
||||
"ZAMyLib": {
|
||||
},
|
||||
"ZAMyLib2": {
|
||||
"deploy": true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("Test", function() {
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
var contractsConfig = {
|
||||
"Test2": {
|
||||
},
|
||||
"ZAMyLib": {
|
||||
},
|
||||
"ZAMyLib2": {
|
||||
"deploy": true
|
||||
}
|
||||
};
|
||||
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("should call library correctly", async function() {
|
||||
let result = await Test2.methods.testAdd().call();
|
||||
assert.equal(result, 3);
|
||||
assert.strictEqual(parseInt(result, 10), 3);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
/*global contract, before, EmbarkSpec, PluginStorage, SimpleStorage, it*/
|
||||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const PluginStorage = embark.require('Embark/contracts/PluginStorage');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"PluginStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
contract("PluginSimpleStorage", function () {
|
||||
this.timeout(0);
|
||||
|
||||
before((done) => {
|
||||
const contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"PluginStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("set SimpleStorage address", async function () {
|
||||
let result = await PluginStorage.methods.simpleStorageAddress().call();
|
||||
assert.equal(result.toString(), SimpleStorage.options.address);
|
||||
|
|
|
@ -1,31 +1,26 @@
|
|||
/*global contract, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
|
||||
contract("SimpleStorage", function() {
|
||||
config({
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
contract("SimpleStorage", function () {
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
|
||||
//config({
|
||||
// node: "http://localhost:8545"
|
||||
//});
|
||||
|
||||
var contractsConfig = {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("should set constructor value", async function() {
|
||||
it("should set constructor value", async function () {
|
||||
let result = await SimpleStorage.methods.storedData().call();
|
||||
assert.equal(result, 100);
|
||||
assert.strictEqual(parseInt(result, 10), 100);
|
||||
});
|
||||
|
||||
it("set storage value", async function() {
|
||||
it("set storage value", async function () {
|
||||
await SimpleStorage.methods.set(150).send();
|
||||
let result = await SimpleStorage.methods.get().call();
|
||||
assert.equal(result, 499650);
|
||||
assert.strictEqual(parseInt(result, 10), 499650);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,86 +1,82 @@
|
|||
/*global describe, it, before*/
|
||||
/*global describe, config, it, embark*/
|
||||
const assert = require('assert');
|
||||
const Token = embark.require('Embark/contracts/Token');
|
||||
const MyToken = embark.require('Embark/contracts/MyToken');
|
||||
const MyToken2 = embark.require('Embark/contracts/MyToken2');
|
||||
const AlreadyDeployedToken = embark.require('Embark/contracts/AlreadyDeployedToken');
|
||||
const Test = embark.require('Embark/contracts/Test');
|
||||
|
||||
describe("Token", function() {
|
||||
|
||||
this.timeout(0);
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
|
||||
//config({
|
||||
// node: "http://localhost:8545"
|
||||
//});
|
||||
|
||||
var contractsConfig = {
|
||||
"ZAMyLib": {
|
||||
},
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
},
|
||||
"Token": {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
"MyToken": {
|
||||
instanceOf: "Token"
|
||||
},
|
||||
"MyToken2": {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
"AlreadyDeployedToken": {
|
||||
"address": "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE",
|
||||
instanceOf: "Token"
|
||||
},
|
||||
"Test": {
|
||||
onDeploy: [
|
||||
"Test.methods.changeAddress('$MyToken').send()"
|
||||
]
|
||||
},
|
||||
"ContractArgs": {
|
||||
"args": {
|
||||
"initialValue": 123,
|
||||
"_addresses": ["$MyToken2", "$SimpleStorage"]
|
||||
}
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
config({
|
||||
contracts: {
|
||||
ZAMyLib: {},
|
||||
SimpleStorage: {
|
||||
args: [100]
|
||||
},
|
||||
AnotherStorage: {
|
||||
args: ["$SimpleStorage"]
|
||||
},
|
||||
Token: {
|
||||
deploy: false,
|
||||
args: [1000]
|
||||
},
|
||||
MyToken: {
|
||||
instanceOf: "Token"
|
||||
},
|
||||
MyToken2: {
|
||||
instanceOf: "Token",
|
||||
args: [2000]
|
||||
},
|
||||
AlreadyDeployedToken: {
|
||||
address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE",
|
||||
instanceOf: "Token"
|
||||
},
|
||||
Test: {
|
||||
onDeploy: ["Test.methods.changeAddress('$MyToken').send()"]
|
||||
},
|
||||
ContractArgs: {
|
||||
args: {
|
||||
initialValue: 123,
|
||||
_addresses: ["$MyToken2", "$SimpleStorage"]
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, () => { done() });
|
||||
});
|
||||
|
||||
it("not deploy Token", function() {
|
||||
assert.equal(Token.address, "");
|
||||
});
|
||||
|
||||
it("not deploy MyToken and MyToken2", function() {
|
||||
assert.notEqual(MyToken.address, "");
|
||||
assert.notEqual(MyToken2.address, "");
|
||||
});
|
||||
|
||||
it("set MyToken Balance correctly", async function() {
|
||||
let result = await MyToken.methods._supply().call();
|
||||
assert.equal(result, 1000);
|
||||
});
|
||||
|
||||
it("set MyToken2 Balance correctly", async function() {
|
||||
let result = await MyToken2.methods._supply().call();
|
||||
assert.equal(result, 2000);
|
||||
});
|
||||
|
||||
it("get right address", function() {
|
||||
assert.equal(AlreadyDeployedToken.address, "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
|
||||
});
|
||||
|
||||
it("should use onDeploy", async function() {
|
||||
let result = await Test.methods.addr().call();
|
||||
assert.equal(result, MyToken.address)
|
||||
});
|
||||
|
||||
},
|
||||
SomeContract: {
|
||||
args: [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe("Token", function () {
|
||||
this.timeout(0);
|
||||
|
||||
it("not deploy Token", function () {
|
||||
assert.strictEqual(Token.address, undefined);
|
||||
});
|
||||
|
||||
it("should deploy MyToken and MyToken2", function () {
|
||||
assert.ok(MyToken.options.address);
|
||||
assert.ok(MyToken2.options.address);
|
||||
});
|
||||
|
||||
it("set MyToken Balance correctly", async function () {
|
||||
let result = await MyToken.methods._supply().call();
|
||||
assert.strictEqual(parseInt(result, 10), 1000);
|
||||
});
|
||||
|
||||
it("set MyToken2 Balance correctly", async function () {
|
||||
let result = await MyToken2.methods._supply().call();
|
||||
assert.strictEqual(parseInt(result, 10), 2000);
|
||||
});
|
||||
|
||||
it("get right address", function () {
|
||||
assert.strictEqual(AlreadyDeployedToken.options.address.toLowerCase(),
|
||||
"0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE".toLowerCase());
|
||||
});
|
||||
|
||||
it("should use onDeploy", async function () {
|
||||
let result = await Test.methods.addr().call();
|
||||
assert.strictEqual(result, MyToken.options.address);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue