Support modifiers
This commit is contained in:
parent
824353fb32
commit
bc5de4ef90
|
@ -128,6 +128,7 @@ class ContractSource {
|
||||||
case 'Assignment':
|
case 'Assignment':
|
||||||
case 'EventDefinition':
|
case 'EventDefinition':
|
||||||
case 'Literal':
|
case 'Literal':
|
||||||
|
case 'PlaceholderStatement':
|
||||||
case 'PragmaDirective':
|
case 'PragmaDirective':
|
||||||
case 'VariableDeclaration':
|
case 'VariableDeclaration':
|
||||||
// We don't need to do anything with these. Just carry on.
|
// We don't need to do anything with these. Just carry on.
|
||||||
|
@ -207,6 +208,7 @@ class ContractSource {
|
||||||
children = node.nodes;
|
children = node.nodes;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'ModifierDefinition':
|
||||||
case 'FunctionDefinition':
|
case 'FunctionDefinition':
|
||||||
// Istanbul only wants the function definition, not the body, so we're
|
// Istanbul only wants the function definition, not the body, so we're
|
||||||
// going to do some fun math here.
|
// going to do some fun math here.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
|
contract Modifiers {
|
||||||
|
uint public storedData;
|
||||||
|
|
||||||
|
constructor(uint initialValue) public {
|
||||||
|
storedData = initialValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier upTo(uint amount, uint desired) {
|
||||||
|
require(
|
||||||
|
desired <= amount,
|
||||||
|
"Value is too high."
|
||||||
|
);
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set(uint x) public upTo(1000, x) {
|
||||||
|
storedData = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get() public view returns (uint retVal) {
|
||||||
|
return storedData;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*global contract, config, it, assert*/
|
||||||
|
const Modifiers = require('Embark/contracts/Modifiers');
|
||||||
|
|
||||||
|
config({
|
||||||
|
contracts: {
|
||||||
|
"Modifiers": {
|
||||||
|
args: [100]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
contract("Modifiers", function() {
|
||||||
|
it("should set constructor value", function(done) {
|
||||||
|
Modifiers.methods.storedData().call().then((result) => {
|
||||||
|
assert.strictEqual(parseInt(result, 10), 100);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("set storage value when valid", function(done) {
|
||||||
|
Modifiers.methods.set(150).send().then(() => {
|
||||||
|
Modifiers.methods.get().call().then((result) => {
|
||||||
|
assert.strictEqual(parseInt(result, 10), 150);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("refuses storage value when invalid", function(done) {
|
||||||
|
Modifiers.methods.set(10000).send().catch((_err) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue