diff --git a/lib/contracts/blockchain.js b/lib/contracts/blockchain.js index fee3a22f8..1d0f0c958 100644 --- a/lib/contracts/blockchain.js +++ b/lib/contracts/blockchain.js @@ -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(); }); } diff --git a/test_apps/test_app/app/contracts/simple_storage.sol b/test_apps/test_app/app/contracts/simple_storage.sol index c72e8e98d..e6e89cd2e 100644 --- a/test_apps/test_app/app/contracts/simple_storage.sol +++ b/test_apps/test_app/app/contracts/simple_storage.sol @@ -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; + } + } diff --git a/test_apps/test_app/config/contracts.js b/test_apps/test_app/config/contracts.js index e6b19e9b7..d6e9be776 100644 --- a/test_apps/test_app/config/contracts.js +++ b/test_apps/test_app/config/contracts.js @@ -21,6 +21,9 @@ module.exports = { fromIndex: 0, args: [ 100 + ], + onDeploy: [ + "SimpleStorage.methods.setRegistar(web3.eth.defaultAccount).send()" ] }, AnotherStorage: { diff --git a/test_apps/test_app/test/simple_storage_spec.js b/test_apps/test_app/test/simple_storage_spec.js index 0eba871ab..2fe59f7c6 100644 --- a/test_apps/test_app/test/simple_storage_spec.js +++ b/test_apps/test_app/test/simple_storage_spec.js @@ -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); + }); + });