Skip to content

Commit

Permalink
fix(tests): jasmine default timeout set to 12 seconds
Browse files Browse the repository at this point in the history
timeouts on testnet occur
  • Loading branch information
dmdeklerk committed Aug 21, 2018
1 parent df97b16 commit 1aa3808
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 72 deletions.
2 changes: 0 additions & 2 deletions src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
* */

import WebSocket from "ws"
import * as Long from "long"
import * as ByteBuffer from "bytebuffer"
import * as utils from "./utils"
import { Buffer } from "buffer"
import { callbackify } from "util"

let MAGIC_NUM = 22102010

Expand Down
1 change: 1 addition & 0 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
import "./jasmine"
import { HeatApiError } from "../src/heat-api"
import { HeatSDK, Configuration } from "../src/heat-sdk"

Expand Down
2 changes: 1 addition & 1 deletion test/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/*
To run tests in the file test/testnet.ts must be actual values for Testnet
*/

import "./jasmine"
import { testnet } from "./testnet"
import { Builder, TransactionImpl } from "../src/builder"
import { Transaction } from "../src/transaction"
Expand Down
64 changes: 22 additions & 42 deletions test/crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,23 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
import "./jasmine"
import * as crypto from "../src/crypto"
import { IEncryptOptions } from "../src/crypto"
import { hexStringToByteArray, stringToByteArray } from "../src/converters"
import * as Long from "long"

let bob = {
secretPhrase:
"floor battle paper consider stranger blind alter blur bless wrote prove cloud",
publicKeyStr:
"ef9baf978860b56d6a0d15638c9af11be687f90230ec839fad762d085fc5651a",
privateKeyStr:
"d0b857ee906717f40917f3a2c2c7e3fa0ffb3bc46edd1606b83f80bccf89065e",
secretPhrase: "floor battle paper consider stranger blind alter blur bless wrote prove cloud",
publicKeyStr: "ef9baf978860b56d6a0d15638c9af11be687f90230ec839fad762d085fc5651a",
privateKeyStr: "d0b857ee906717f40917f3a2c2c7e3fa0ffb3bc46edd1606b83f80bccf89065e",
account: "2068178321230336428"
}

let alice = {
secretPhrase: "user3",
publicKeyStr:
"4376219788e7d1946ad377196fd7103958d3d6d6618dc93d2d0d6b4f717b641d", //???
privateKeyStr:
"5860faf02b6bc6222ba5aca523560f0e364ccd8b67bee486fe8bf7c01d492c4b",
publicKeyStr: "4376219788e7d1946ad377196fd7103958d3d6d6618dc93d2d0d6b4f717b641d", //???
privateKeyStr: "5860faf02b6bc6222ba5aca523560f0e364ccd8b67bee486fe8bf7c01d492c4b",
account: "1522541402758811473"
}

Expand Down Expand Up @@ -75,9 +71,7 @@ describe("crypto.fullNameToHash test", () => {
expect(crypto.fullNameToHash).toBeInstanceOf(Function)
})
it("returns a full name hash", () => {
expect(crypto.fullNameToHash("[email protected]")).toBe(
"8932144534527668929"
)
expect(crypto.fullNameToHash("[email protected]")).toBe("8932144534527668929")
})
})

Expand All @@ -87,9 +81,7 @@ describe("crypto.fullNameToLong test", () => {
})
it("returns a full name hash", () => {
let bytes = stringToByteArray("[email protected]")
expect(crypto.fullNameToLong(bytes)).toEqual(
Long.fromString("8932144534527668929")
)
expect(crypto.fullNameToLong(bytes)).toEqual(Long.fromString("8932144534527668929"))
})
})

Expand All @@ -111,12 +103,8 @@ describe("crypto.secretPhraseToPublicKey test", () => {
expect(crypto.secretPhraseToPublicKey).toBeInstanceOf(Function)
})
it("returns public key of secret phrase", () => {
expect(crypto.secretPhraseToPublicKey(bob.secretPhrase)).toBe(
bob.publicKeyStr
)
expect(crypto.secretPhraseToPublicKey(alice.secretPhrase)).toBe(
alice.publicKeyStr
)
expect(crypto.secretPhraseToPublicKey(bob.secretPhrase)).toBe(bob.publicKeyStr)
expect(crypto.secretPhraseToPublicKey(alice.secretPhrase)).toBe(alice.publicKeyStr)
})
})

Expand Down Expand Up @@ -146,9 +134,7 @@ describe("crypto.getAccountIdFromPublicKey test", () => {
})
it("returns account id", () => {
expect(crypto.getAccountIdFromPublicKey(bob.publicKeyStr)).toBe(bob.account)
expect(crypto.getAccountIdFromPublicKey(alice.publicKeyStr)).toBe(
alice.account
)
expect(crypto.getAccountIdFromPublicKey(alice.publicKeyStr)).toBe(alice.account)
})
})

Expand Down Expand Up @@ -222,11 +208,7 @@ describe("crypto.encryptBinaryNote test", () => {
}

return crypto
.encryptBinaryNote(
stringToByteArray(text),
options,
bob.secretPhrase /*todo with true*/
)
.encryptBinaryNote(stringToByteArray(text), options, bob.secretPhrase /*todo with true*/)
.then(encrypted => {
let decrypted = crypto.decryptMessage(
encrypted.message,
Expand All @@ -246,18 +228,16 @@ describe("crypto.encryptMessage, crypto.decryptMessage test", () => {
})
it("encrypts, decrypts message", () => {
let text = "qwerty ♠═~☺"
return crypto
.encryptMessage(text, bob.publicKeyStr, bob.secretPhrase)
.then(encrypted => {
let decrypted = crypto.decryptMessage(
encrypted.data,
encrypted.nonce,
bob.publicKeyStr,
bob.secretPhrase
)
expect(encrypted.isText).toBe(true)
return expect(decrypted).toBe(text)
})
return crypto.encryptMessage(text, bob.publicKeyStr, bob.secretPhrase).then(encrypted => {
let decrypted = crypto.decryptMessage(
encrypted.data,
encrypted.nonce,
bob.publicKeyStr,
bob.secretPhrase
)
expect(encrypted.isText).toBe(true)
return expect(decrypted).toBe(text)
})
})
})

Expand Down
18 changes: 9 additions & 9 deletions test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
import "./jasmine"
import fetch, { Headers, Request, Response } from "node-fetch"

/**
* To access `fetch` in your tests and nodejs modules include
* To access `fetch` in your tests and nodejs modules include
* require('es6-promise').polyfill();require('isomorphic-fetch') at the top
* of your module.
* of your module.
* To access `fetch` in a browser simply refer to the global `fetch` method.
*
*
* Links:
*
*
* About async tests
* https://facebook.github.io/jest/docs/en/tutorial-async.html
*
*
* About using fetch
* https://developers.google.com/web/updates/2015/03/introduction-to-fetch
* https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
*
*
* About fetch
* Fetch is natively supported in both latest firefox and chrome and is meant
* Fetch is natively supported in both latest firefox and chrome and is meant
* as a native standardized follow up to XMLHttpRequest.
*/

Expand All @@ -47,8 +48,7 @@ import fetch, { Headers, Request, Response } from "node-fetch"
function searchParams(params: { [key: string]: string }): string {
let result: string[] = []
for (var key in params) {
if (params.hasOwnProperty(key))
result.push(`${key}=${encodeURIComponent(params[key])}`)
if (params.hasOwnProperty(key)) result.push(`${key}=${encodeURIComponent(params[key])}`)
}
return result.join("&")
}
Expand Down
5 changes: 2 additions & 3 deletions test/heat-sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
import "./jasmine"
import { HeatSDK } from "../src/heat-sdk"

describe("Export default test", () => {
Expand All @@ -28,8 +29,6 @@ describe("Export default test", () => {
expect(heatsdk).toBeTruthy()
})
it("has a crypto property with exported methods", () => {
expect(heatsdk.crypto.getAccountId("secret phrase")).toBe(
"7567221445300685906"
)
expect(heatsdk.crypto.getAccountId("secret phrase")).toBe("7567221445300685906")
})
})
1 change: 1 addition & 0 deletions test/jasmine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 12000
7 changes: 2 additions & 5 deletions test/random-bytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
import "./jasmine"
import { randomBytes } from "../src/random-bytes"

describe("randomBytes", () => {
Expand All @@ -39,11 +40,7 @@ describe("randomBytes", () => {
])
})
it("never returns the same bytes", () => {
return Promise.all([
randomBytes(10),
randomBytes(10),
randomBytes(10)
]).then(values => {
return Promise.all([randomBytes(10), randomBytes(10), randomBytes(10)]).then(values => {
expect(values[0]).not.toEqual(values[1])
expect(values[1]).not.toEqual(values[2])
return expect(values[0]).not.toEqual(values[2])
Expand Down
17 changes: 8 additions & 9 deletions test/secret-generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./jasmine"
import { SecretGenerator } from "../src/secret-generator"

describe("SecretGenerator.generate test", () => {
Expand All @@ -18,14 +19,12 @@ describe("SecretGenerator.generate test", () => {
})
it("returns unique secret phrases", () => {
let generator = new SecretGenerator()
return Promise.all([
generator.generate(),
generator.generate(),
generator.generate()
]).then(values => {
expect(values[0]).not.toEqual(values[1])
expect(values[1]).not.toEqual(values[2])
return expect(values[0]).not.toEqual(values[2])
})
return Promise.all([generator.generate(), generator.generate(), generator.generate()]).then(
values => {
expect(values[0]).not.toEqual(values[1])
expect(values[1]).not.toEqual(values[2])
return expect(values[0]).not.toEqual(values[2])
}
)
})
})
1 change: 1 addition & 0 deletions test/socket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* */
import "./jasmine"
import { HeatSDK, Configuration } from "../src/heat-sdk"
import {
BroadcastRequest,
Expand Down
2 changes: 1 addition & 1 deletion test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
To run tests in the file test/testnet.ts must be actual values for Testnet.
The tests passes until the account balance has the money.
*/

import "./jasmine"
import { testnet } from "./testnet"
import { Configuration, HeatSDK } from "../src/heat-sdk"
import { IBroadcastOutput } from "../src/transaction"
Expand Down
1 change: 1 addition & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./jasmine"
import * as utils from "../src/utils"

describe("utils.unformat test", () => {
Expand Down

0 comments on commit 1aa3808

Please sign in to comment.