Skip to content
Snippets Groups Projects
Commit 43f1046b authored by Jono Wenger's avatar Jono Wenger
Browse files

Fix WaitForNetwork

parent 45c57d9a
No related branches found
No related tags found
1 merge request!6XX-4050 / Send E2E test
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn")
// Client specific parameters // Client specific parameters
const recipientContactFile = '<xxc(2)I71lyX8LvKP6cJhedliFLIKzXN/2ArmBAfAxkk1QapADrgZ7Ugdw/BAr6RDo4K2MfHn7e06Kru7jW05ROtaaoNSyMIB3R77BIJy7xB/fvkzteTpxxmHtZdXPt9UpYVA9WKzbM57vkmy+U6BlRJIrN97tAlWbODIG1FGpjWI/BCdqwaLgu0wTYLzzEw38NNyax0E2MnvURgQoSfnX5V+m+Qd2sJBqfBKi9tlLuNcaFI+TGyKGbZdSs4AZdiL/Xm94w1/id4SDEoV73RaJb3RH+W+rEMIl1SnZ4U6Ifo39cZfRKevL2mXUZj/SE0NWGl4+10Jovy0Hp6NoW2iMH4zB30xv3fqyp8ATAYXYYO5ToFmHvP1fRLq7TKa+WtGnO70uiykBaYl219WcGYIz4jXDYyN3yNnOhihKo2tauyC0qGeGCSoACDxvzLGTHxHkS/cDA92L0MEsiXy3HIuv5+OYZBuiWl1dLxjkUKKo4f3VyDUaWjrlUFqVO95X29+Zuw++AK1TVnWtt/F4J+L91hwEfDGxYn5f2I6tNKLXnyXlPVDpa1EE6+d1LWznfXVHHzL58lBIK0Yk9MKGHQAAAgA7OaXVXCYpP2SfHIEp3s0tRA==xxc>'; const recipientContactFile = '<xxc(2)vL/3ePQKC3YZ/j5DjIdLC9TwEgB19PPvNSiJzv+TR4oDrgZ7Ugdw/BAr6Y/Ci8g9/nJQV3MVVMwJGVKoQSq4LVrJum1JBNHVwRJl/03bzAhV+YUnDYXEva1krP31gZ25pwuOlLqKyxy4gxicZZOKv5xcaqgIZeALbIUxpgAclHT1S/U1OTjdC9GnZoi+Ta/ftZhFcB/b8YIqLnp9+N9QGBCqYImr371cfhnSVSVNUhgKEReJkvQzfeeLXp6LHs9al9jvq8OR/uMLzjP+MqPaVc8/AXoPUMTSsQMhTQrbcgN7auK4mP0RcbIviKU1MIt8RGXrhLgPa2l1V1IinuMkpKoqwkolR13ZN6evw3rl57K7XEwK8di5bs2EisOceLd+IJPhQUxceaytKGCuqqOTlOj8f+tet4yZ92h//u3tWIIB7IoLyipxIj1Tq6Q+UDarf5+ReqIupTmiOjIxPJZxRqoMZGO45CcyPPdFEEMhozbH0WxyCruwKD352ZG9aKGoq97VclLxDOgE7Dx/oGmA3YvaJK5lUQPGO5egLHn23qmP7IN/8Pxn6D84Lovt8YddR4jjlIuY4qAhdAAAAgA7HsmlZr0oNSUMhb6OyUMn0A==xxc>';
const myContactFileName = ''; const myContactFileName = '';
const statePath = 'statePathSender'; const statePath = 'statePathSender';
const statePass = 'password'; const statePass = 'password';
......
...@@ -56,7 +56,7 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf, ...@@ -56,7 +56,7 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf,
htmlConsole.log("Getting reception identity.") htmlConsole.log("Getting reception identity.")
identity = LoadReceptionIdentity(identityStorageKey, net.GetID()); identity = LoadReceptionIdentity(identityStorageKey, net.GetID());
} catch (e) { } catch (e) {
htmlConsole.log("No reception identity found. Generating a new one: " + e) htmlConsole.log("No reception identity found. Generating a new one.")
// If no extant xxdk.ReceptionIdentity, generate and store a new one // If no extant xxdk.ReceptionIdentity, generate and store a new one
identity = net.MakeReceptionIdentity(); identity = net.MakeReceptionIdentity();
...@@ -109,27 +109,26 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf, ...@@ -109,27 +109,26 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf,
htmlConsole.log("Started network follower") htmlConsole.log("Started network follower")
stopNetworkFollowerBtn.style.display = 'block'; stopNetworkFollowerBtn.style.display = 'block';
stopNetworkFollowerBtn.addEventListener('click', () => { stopNetworkFollowerBtn.addEventListener('click', async () => {
htmlConsole.log("Stopping network follower") htmlConsole.log("Stopping network follower")
net.StopNetworkFollower() try {
}) await net.StopNetworkFollower()
} catch (e) {
// Provide a callback that will be signalled when network health status changes htmlConsole.log("Failed to stop network follower: " + e)
let health = false
net.AddHealthCallback({
Callback: function (healthy) {
health = healthy;
} }
}); })
// Wait for network to become healthy
htmlConsole.log("Waiting for network to be healthy") htmlConsole.log("Waiting for network to be healthy")
try { net.WaitForNetwork(25000).then(
await sleepUntil(() => health === true, 25000); () => {
} catch { htmlConsole.log("Network is healthy")
htmlConsole.error("Timed out. Network is not healthy: " + health) },
throw new Error("Timed out. Network is not healthy: " + health) () => {
htmlConsole.error("Timed out. Network is not healthy.")
throw new Error("Timed out. Network is not healthy.")
} }
htmlConsole.log("Network is healthy: " + health) )
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
...@@ -160,7 +159,7 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf, ...@@ -160,7 +159,7 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf,
if (recipientContactFile !== '') { if (recipientContactFile !== '') {
let exists = false; let exists = false;
htmlConsole.log("getting ID from contact") htmlConsole.log("getting ID from contact")
const recipientContactID = GetIDFromContact(recipientContactFile); const recipientContactID = GetIDFromContact(enc.encode(recipientContactFile));
const recipientContactIDBase64 = Uint8ArrayToBase64(recipientContactID) const recipientContactIDBase64 = Uint8ArrayToBase64(recipientContactID)
htmlConsole.log("Checking if partner " + recipientContactIDBase64 + " exists") htmlConsole.log("Checking if partner " + recipientContactIDBase64 + " exists")
...@@ -195,6 +194,8 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf, ...@@ -195,6 +194,8 @@ async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf,
throw new Error("Did not receive confirm: " + confirm) throw new Error("Did not receive confirm: " + confirm)
} }
console.log("confirmContact: " + confirmContact)
console.log("confirmContact: " + dec.decode(confirmContact))
const confirmContactID = GetIDFromContact(confirmContact) const confirmContactID = GetIDFromContact(confirmContact)
if (!Uint8ArrayEquals(recipientContactID, confirmContactID)) { if (!Uint8ArrayEquals(recipientContactID, confirmContactID)) {
htmlConsole.log("contact ID from confirmation " + htmlConsole.log("contact ID from confirmation " +
......
...@@ -88,9 +88,18 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { ...@@ -88,9 +88,18 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} {
// - args[0] - timeout when stopping threads in milliseconds (int) // - args[0] - timeout when stopping threads in milliseconds (int)
// //
// Returns: // Returns:
// - returns true if the network is healthy (boolean) // - A promise that resolves if the network is healthy and rejects if the
// network is not healthy.
func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} { func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} {
return c.api.WaitForNetwork(args[0].Int()) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) {
if c.api.WaitForNetwork(args[0].Int()) {
resolve()
} else {
reject()
}
}
return utils.CreatePromise(promiseFn)
} }
// NetworkFollowerStatus gets the state of the network follower. It returns a // NetworkFollowerStatus gets the state of the network follower. It returns a
......
...@@ -135,13 +135,13 @@ func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) interface{} { ...@@ -135,13 +135,13 @@ func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) interface{} {
// GetIDFromContact returns the ID in the [contact.Contact] object. // GetIDFromContact returns the ID in the [contact.Contact] object.
// //
// Parameters: // Parameters:
// - args[0] - marshalled bytes of [contact.Contact] (string) // - args[0] - marshalled bytes of [contact.Contact] (Uint8Array)
// //
// Returns: // Returns:
// - marshalled [id.ID] object (Uint8Array) // - marshalled [id.ID] object (Uint8Array)
// - throws a TypeError if loading the ID from the contact file fails // - throws a TypeError if loading the ID from the contact file fails
func GetIDFromContact(_ js.Value, args []js.Value) interface{} { func GetIDFromContact(_ js.Value, args []js.Value) interface{} {
cID, err := bindings.GetIDFromContact([]byte(args[0].String())) cID, err := bindings.GetIDFromContact(utils.CopyBytesToGo(args[0]))
if err != nil { if err != nil {
utils.Throw(utils.TypeError, err) utils.Throw(utils.TypeError, err)
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment