Merge pull request #746 from embark-framework/bug_fix/tests-ws-bug

Fix test_app with a WS node
This commit is contained in:
Iuri Matias 2018-08-24 15:53:54 -04:00 committed by GitHub
commit a0d864b8ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 9 deletions

View File

@ -20,6 +20,8 @@ class Provider {
self.provider = new this.web3.providers.HttpProvider(self.web3Endpoint);
} else if (this.type === 'ws') {
self.provider = new this.web3.providers.WebsocketProvider(self.web3Endpoint, {headers: {Origin: "embark"}});
self.provider.on('error', e => self.logger.error('Websocket Error', e));
self.provider.on('end', e => self.logger.error('Websocket connection ended', e));
} else {
return callback(__("contracts config error: unknown deployment type %s", this.type));
}

View File

@ -40,6 +40,10 @@ const parseResponse = function (ipc, resBody) {
commList[jsonO.id].transactionHash = jsonO.result;
transactions[jsonO.result] = {commListId: jsonO.id};
} else if (receipts[jsonO.id] && jsonO.result && jsonO.result.blockNumber) {
// TODO find out why commList[receipts[jsonO.id]] is sometimes not defined
if (!commList[receipts[jsonO.id]]) {
commList[receipts[jsonO.id]] = {};
}
commList[receipts[jsonO.id]].blockNumber = jsonO.result.blockNumber;
commList[receipts[jsonO.id]].gasUsed = jsonO.result.gasUsed;
commList[receipts[jsonO.id]].status = jsonO.result.status;

View File

@ -327,11 +327,13 @@ class Test {
if (newContract.options) {
newContract.options.from = self.web3.eth.defaultAccount;
newContract.options.data = contract.code;
if (!newContract.options.data.startsWith('0x')) {
newContract.options.data = '0x' + newContract.options.data;
}
newContract.options.gas = 6000000;
}
Object.setPrototypeOf(self.contracts[contract.className], newContract);
Object.assign(self.contracts[contract.className], newContract);
eachCb();
}, (err) => {

View File

@ -23,9 +23,6 @@ contract SimpleStorage is Ownable {
function set(uint x) public {
storedData = x;
for(uint i = 0; i < 1000; i++) {
storedData += i;
}
Assert.triggerEvent(true, "hi");
}

View File

@ -16,7 +16,7 @@ contract("SimpleStorage Deploy", function () {
it("set storage value", async function () {
await SimpleStorageInstance.methods.set(150).send();
let result = await SimpleStorageInstance.methods.get().call();
assert.strictEqual(parseInt(result, 10), 499650);
assert.strictEqual(parseInt(result, 10), 150);
});
});

View File

@ -1,6 +1,7 @@
/*global contract, config, it, assert, web3*/
const SimpleStorage = require('Embark/contracts/SimpleStorage');
let accounts;
const Utils = require('embarkjs').Utils;
config({
contracts: {
@ -21,10 +22,16 @@ contract("SimpleStorage", function () {
assert.strictEqual(parseInt(result, 10), 100);
});
it("set storage value", async function () {
await SimpleStorage.methods.set(150).send();
let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 499650);
it("set storage value", function (done) {
// await SimpleStorage.methods.set(150).send();
Utils.secureSend(web3, SimpleStorage.methods.set(150), {}, false, async function(err) {
if (err) {
return done(err);
}
let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 150);
done();
});
});
it("should set defaultAccount", async function () {