fix setting default account

This commit is contained in:
Iuri Matias 2018-06-06 10:39:02 -04:00
parent f44ed981b5
commit cd6dcb7548
4 changed files with 21 additions and 2 deletions

View File

@ -240,10 +240,12 @@ class Blockchain {
});
},
function checkAccounts(next) {
self.getAccounts(function(err, _accounts) {
self.getAccounts(function(err, accounts) {
if (err) {
return next(NO_NODE_ERROR);
}
self.web3.defaultAccount = accounts[0];
self.registerWeb3Object();
return next();
});
}

View File

@ -12,6 +12,7 @@ library Assert {
contract SimpleStorage is Ownable {
uint public storedData;
address public registar;
function() public payable { }
@ -39,4 +40,8 @@ contract SimpleStorage is Ownable {
return "hello";
}
function setRegistar(address x) public {
registar = x;
}
}

View File

@ -21,6 +21,9 @@ module.exports = {
fromIndex: 0,
args: [
100
],
onDeploy: [
"SimpleStorage.methods.setRegistar(web3.eth.defaultAccount).send()"
]
},
AnotherStorage: {

View File

@ -5,7 +5,10 @@ const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
config({
contracts: {
"SimpleStorage": {
args: [100]
args: [100],
onDeploy: [
"SimpleStorage.methods.setRegistar(web3.eth.defaultAccount).send()"
]
}
}
});
@ -23,4 +26,10 @@ contract("SimpleStorage", function () {
let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 499650);
});
it("should set defaultAccount", async function () {
let result = await SimpleStorage.methods.registar().call();
assert.strictEqual(result, web3.eth.defaultAccount);
});
});