Merge pull request #346 from richard-ramos/develop
Updating documentation related to smart contracts and tests
This commit is contained in:
commit
323e2d74d1
|
@ -1,8 +1,8 @@
|
||||||
Testing Ethereum Contracts
|
Testing Ethereum Contracts
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
You can run specs with ``embark test``, it will run any test files under
|
You can run specs with ``embark test``, it will run all the test files under
|
||||||
``test/``.
|
``test/``. You can run a specific test file with ``embark test <path/test_filename.js>
|
||||||
|
|
||||||
Embark includes a testing lib to fastly run & test your contracts in a
|
Embark includes a testing lib to fastly run & test your contracts in a
|
||||||
EVM.
|
EVM.
|
||||||
|
@ -120,3 +120,48 @@ and initialize the testing functionality. Below is an example using mocha:
|
||||||
|
|
||||||
``mocha test/simple_storage_spec.js --no-timeouts``
|
``mocha test/simple_storage_spec.js --no-timeouts``
|
||||||
|
|
||||||
|
**accessing accounts**
|
||||||
|
|
||||||
|
The callback used in the function ``deployAll`` will let you access the accounts configured in the EVM.
|
||||||
|
You can assign them to a variable and use them in your tests.
|
||||||
|
|
||||||
|
.. code:: javascript
|
||||||
|
|
||||||
|
var accountArr;
|
||||||
|
EmbarkSpec.deployAll(contractsConfig, (accounts) => {
|
||||||
|
accountArr = accounts;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
**creating contract instances in your tests**
|
||||||
|
|
||||||
|
Embark handles the deployment of your contracts through the function ``deployAll``.
|
||||||
|
However you can use ``web3.eth.contract`` for creating instances of your contracts manually.
|
||||||
|
|
||||||
|
.. code:: javascript
|
||||||
|
|
||||||
|
var simpleStorageJson = require('../dist/contracts/SimpleStorage.json');
|
||||||
|
var accountArr;
|
||||||
|
var simpleStorage;
|
||||||
|
|
||||||
|
describe("SimpleStorage", function() {
|
||||||
|
this.timeout(0);
|
||||||
|
before(function(done) {
|
||||||
|
EmbarkSpec.deployAll({}, (accounts) => {
|
||||||
|
accountArr = accounts;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should deploy a contract instance", function(done) {
|
||||||
|
var simpleStorageContract = new web3.eth.Contract(simpleStorageJson.abi);
|
||||||
|
simpleStorageContract.deploy({data: simpleStorageJson.code, arguments: [100]})
|
||||||
|
.send({from: accountArr[0], gas: 5000000, gasPrice: 1})
|
||||||
|
.then(function(contractInstance){
|
||||||
|
simpleStorage = contractInstance;
|
||||||
|
simpleStorage.setProvider(web3.currentProvider);
|
||||||
|
assert(simpleStorage.options.address != null);
|
||||||
|
})
|
||||||
|
.finally(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -47,7 +47,8 @@ arguments:
|
||||||
"args": [
|
"args": [
|
||||||
100
|
100
|
||||||
],
|
],
|
||||||
"gas": 800000
|
"gas": 800000,
|
||||||
|
"gasPrice": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,3 +178,23 @@ instead.
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
You can specify actions to do after the deployment of a contract using the "onDeploy" parameter.
|
||||||
|
|
||||||
|
| "onDeploy" - should be an array of javascript instructions that will be evaluated and executed
|
||||||
|
|
||||||
|
.. code:: json
|
||||||
|
|
||||||
|
# config/contracts.json
|
||||||
|
{
|
||||||
|
"development": {
|
||||||
|
"gas": "auto",
|
||||||
|
"contracts": {
|
||||||
|
"SimpleStorage": {
|
||||||
|
"args": [
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"onDeploy": ["SimpleStorage.methods.set(150).send()"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue