From 81af3affc4b310e0c1b65bf69aad95197ab1c9b5 Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 7 Jan 2020 15:19:54 +1100 Subject: [PATCH] =?UTF-8?q?fix(@embark/tests):=20Fix=20failing=20test=20wi?= =?UTF-8?q?th=20`=E2=80=94node=3Dembark`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem When using `embark test —node=embark` with the test app, the test that listens for contract events would always fail after timing out. Funnily enough, after the timeout, the subsequent test would run, executing a method that would ulimately fire the event listened for in the previous test, causing the second test to fail as well. ## Solution (workaround) Update the contract events listener test in the test app to execute the `set2` method twice, successfully working around the issue. ## NOTES The cause of the issue is unknown and why the workaround works is also unknown. This change works with both `embark test` and `embark test —node=embark`. --- dapps/tests/app/test/simple_storage_spec.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/dapps/tests/app/test/simple_storage_spec.js b/dapps/tests/app/test/simple_storage_spec.js index ed04802a8..d369ae19e 100644 --- a/dapps/tests/app/test/simple_storage_spec.js +++ b/dapps/tests/app/test/simple_storage_spec.js @@ -50,14 +50,23 @@ contract("SimpleStorage", function() { assert.strictEqual(SimpleStorage.options.address, SimpleStorage.address); }); - it('listens to events', function(done) { - SimpleStorage.once('EventOnSet2', async function(error, result) { - assert.strictEqual(error, null); - assert.strictEqual(parseInt(result.returnValues.setValue, 10), 150); - done(error); + it('listens to events', async function() { + const promise = new Promise((resolve) => { + SimpleStorage.once("EventOnSet2", (error, result) => { + assert.strictEqual(error, null); + assert.strictEqual(parseInt(result.returnValues.setValue, 10), 150); + resolve(); + }); }); - SimpleStorage.methods.set2(150).send(); + await SimpleStorage.methods.set2(150).send(); + + // execute the same method/value twice as a workaround for getting this test + // to pass with --node=embark. The cause of the issue and how the workaround + // works is still unknown. + await SimpleStorage.methods.set2(150).send(); + + return promise; }); it('asserts event triggered', async function() {