mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 16:15:49 +00:00
Run prettier (yarn format)
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
|||||||
RippledNotInitializedError,
|
RippledNotInitializedError,
|
||||||
RippleError
|
RippleError
|
||||||
} from './errors'
|
} from './errors'
|
||||||
import {ExponentialBackoff} from './backoff';
|
import {ExponentialBackoff} from './backoff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConnectionOptions is the configuration for the Connection class.
|
* ConnectionOptions is the configuration for the Connection class.
|
||||||
@@ -387,7 +387,7 @@ export class Connection extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
private _heartbeat = () => {
|
private _heartbeat = () => {
|
||||||
return this.request({command: 'ping'}).catch(() => {
|
return this.request({command: 'ping'}).catch(() => {
|
||||||
this.reconnect().catch((error) => {
|
this.reconnect().catch(error => {
|
||||||
this.emit('error', 'reconnect', error.message, error)
|
this.emit('error', 'reconnect', error.message, error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -550,8 +550,8 @@ export class Connection extends EventEmitter {
|
|||||||
* If no open websocket connection exists, resolve with no code (`undefined`).
|
* If no open websocket connection exists, resolve with no code (`undefined`).
|
||||||
*/
|
*/
|
||||||
disconnect(): Promise<number | undefined> {
|
disconnect(): Promise<number | undefined> {
|
||||||
clearTimeout(this._reconnectTimeoutID);
|
clearTimeout(this._reconnectTimeoutID)
|
||||||
this._reconnectTimeoutID = null;
|
this._reconnectTimeoutID = null
|
||||||
if (this._state === WebSocket.CLOSED || !this._ws) {
|
if (this._state === WebSocket.CLOSED || !this._ws) {
|
||||||
return Promise.resolve(undefined)
|
return Promise.resolve(undefined)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,14 +59,14 @@ const AccountFlags = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Settings {
|
export interface Settings {
|
||||||
passwordSpent?: boolean,
|
passwordSpent?: boolean
|
||||||
requireDestinationTag?: boolean,
|
requireDestinationTag?: boolean
|
||||||
requireAuthorization?: boolean,
|
requireAuthorization?: boolean
|
||||||
depositAuth?: boolean,
|
depositAuth?: boolean
|
||||||
disallowIncomingXRP?: boolean,
|
disallowIncomingXRP?: boolean
|
||||||
disableMasterKey?: boolean,
|
disableMasterKey?: boolean
|
||||||
noFreeze?: boolean,
|
noFreeze?: boolean
|
||||||
globalFreeze?: boolean,
|
globalFreeze?: boolean
|
||||||
defaultRipple?: boolean
|
defaultRipple?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {validate, constants, ensureClassicAddress} from '../common'
|
|||||||
import {FormattedSettings} from '../common/types/objects'
|
import {FormattedSettings} from '../common/types/objects'
|
||||||
import {AccountInfoResponse} from '../common/types/commands'
|
import {AccountInfoResponse} from '../common/types/commands'
|
||||||
import {RippleAPI} from '..'
|
import {RippleAPI} from '..'
|
||||||
import { Settings } from '../common/constants'
|
import {Settings} from '../common/constants'
|
||||||
|
|
||||||
const AccountFlags = constants.AccountFlags
|
const AccountFlags = constants.AccountFlags
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,10 @@ export interface GenerateAddressOptions {
|
|||||||
function generateAddressAPI(options: GenerateAddressOptions): GeneratedAddress {
|
function generateAddressAPI(options: GenerateAddressOptions): GeneratedAddress {
|
||||||
validate.generateAddress({options})
|
validate.generateAddress({options})
|
||||||
try {
|
try {
|
||||||
const generateSeedOptions: { entropy?: Uint8Array; algorithm?: "ecdsa-secp256k1" | "ed25519"; } = {
|
const generateSeedOptions: {
|
||||||
|
entropy?: Uint8Array
|
||||||
|
algorithm?: 'ecdsa-secp256k1' | 'ed25519'
|
||||||
|
} = {
|
||||||
algorithm: options.algorithm
|
algorithm: options.algorithm
|
||||||
}
|
}
|
||||||
if (options.entropy) {
|
if (options.entropy) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import assert from 'assert-diff'
|
import assert from 'assert-diff'
|
||||||
import responses from '../../fixtures/responses'
|
import responses from '../../fixtures/responses'
|
||||||
import {TestSuite} from '../../utils'
|
import {TestSuite} from '../../utils'
|
||||||
import { GenerateAddressOptions } from '../../../src/offline/generate-address'
|
import {GenerateAddressOptions} from '../../../src/offline/generate-address'
|
||||||
const {generateAddress: RESPONSE_FIXTURES} = responses
|
const {generateAddress: RESPONSE_FIXTURES} = responses
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +10,7 @@ const {generateAddress: RESPONSE_FIXTURES} = responses
|
|||||||
* - Check out "test/api/index.ts" for more information about the test runner.
|
* - Check out "test/api/index.ts" for more information about the test runner.
|
||||||
*/
|
*/
|
||||||
export default <TestSuite>{
|
export default <TestSuite>{
|
||||||
'generateAddress': async (api) => {
|
'generateAddress': async api => {
|
||||||
// GIVEN entropy of all zeros
|
// GIVEN entropy of all zeros
|
||||||
function random() {
|
function random() {
|
||||||
return new Array(16).fill(0)
|
return new Array(16).fill(0)
|
||||||
@@ -25,7 +25,7 @@ export default <TestSuite>{
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress invalid entropy': async (api) => {
|
'generateAddress invalid entropy': async api => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
// GIVEN entropy of 1 byte
|
// GIVEN entropy of 1 byte
|
||||||
function random() {
|
function random() {
|
||||||
@@ -40,7 +40,7 @@ export default <TestSuite>{
|
|||||||
}, api.errors.UnexpectedError)
|
}, api.errors.UnexpectedError)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with no options object': async (api) => {
|
'generateAddress with no options object': async api => {
|
||||||
// GIVEN no options
|
// GIVEN no options
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
@@ -51,7 +51,7 @@ export default <TestSuite>{
|
|||||||
assert(account.secret.startsWith('s'), 'Secret must start with `s`')
|
assert(account.secret.startsWith('s'), 'Secret must start with `s`')
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with empty options object': async (api) => {
|
'generateAddress with empty options object': async api => {
|
||||||
// GIVEN an empty options object
|
// GIVEN an empty options object
|
||||||
const options = {}
|
const options = {}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ export default <TestSuite>{
|
|||||||
assert(account.secret.startsWith('s'), 'Secret must start with `s`')
|
assert(account.secret.startsWith('s'), 'Secret must start with `s`')
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ecdsa-secp256k1`': async (api) => {
|
'generateAddress with algorithm `ecdsa-secp256k1`': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1'
|
// GIVEN we want to use 'ecdsa-secp256k1'
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1'}
|
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1'}
|
||||||
|
|
||||||
@@ -72,11 +72,19 @@ export default <TestSuite>{
|
|||||||
|
|
||||||
// THEN we get an object with an address starting with 'r' and a secret starting with 's' (not 'sEd')
|
// THEN we get an object with an address starting with 'r' and a secret starting with 's' (not 'sEd')
|
||||||
assert(account.address.startsWith('r'), 'Address must start with `r`')
|
assert(account.address.startsWith('r'), 'Address must start with `r`')
|
||||||
assert.deepEqual(account.secret.slice(0, 1), 's', `Secret ${account.secret} must start with 's'`)
|
assert.deepEqual(
|
||||||
assert.notStrictEqual(account.secret.slice(0, 3), 'sEd', `secp256k1 secret ${account.secret} must not start with 'sEd'`)
|
account.secret.slice(0, 1),
|
||||||
|
's',
|
||||||
|
`Secret ${account.secret} must start with 's'`
|
||||||
|
)
|
||||||
|
assert.notStrictEqual(
|
||||||
|
account.secret.slice(0, 3),
|
||||||
|
'sEd',
|
||||||
|
`secp256k1 secret ${account.secret} must not start with 'sEd'`
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ed25519`': async (api) => {
|
'generateAddress with algorithm `ed25519`': async api => {
|
||||||
// GIVEN we want to use 'ed25519'
|
// GIVEN we want to use 'ed25519'
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519'}
|
const options: GenerateAddressOptions = {algorithm: 'ed25519'}
|
||||||
|
|
||||||
@@ -85,12 +93,19 @@ export default <TestSuite>{
|
|||||||
|
|
||||||
// THEN we get an object with an address starting with 'r' and a secret starting with 'sEd'
|
// THEN we get an object with an address starting with 'r' and a secret starting with 'sEd'
|
||||||
assert(account.address.startsWith('r'), 'Address must start with `r`')
|
assert(account.address.startsWith('r'), 'Address must start with `r`')
|
||||||
assert.deepEqual(account.secret.slice(0, 3), 'sEd', `Ed25519 secret ${account.secret} must start with 'sEd'`)
|
assert.deepEqual(
|
||||||
|
account.secret.slice(0, 3),
|
||||||
|
'sEd',
|
||||||
|
`Ed25519 secret ${account.secret} must start with 'sEd'`
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ecdsa-secp256k1` and given entropy': async (api) => {
|
'generateAddress with algorithm `ecdsa-secp256k1` and given entropy': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1', entropy: new Array(16).fill(0)}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ecdsa-secp256k1',
|
||||||
|
entropy: new Array(16).fill(0)
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
const account = api.generateAddress(options)
|
const account = api.generateAddress(options)
|
||||||
@@ -99,28 +114,34 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, responses.generateAddress)
|
assert.deepEqual(account, responses.generateAddress)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ed25519` and given entropy': async (api) => {
|
'generateAddress with algorithm `ed25519` and given entropy': async api => {
|
||||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519', entropy: new Array(16).fill(0)}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ed25519',
|
||||||
|
entropy: new Array(16).fill(0)
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
const account = api.generateAddress(options)
|
const account = api.generateAddress(options)
|
||||||
|
|
||||||
// THEN we get the expected return value
|
// THEN we get the expected return value
|
||||||
assert.deepEqual(account, {
|
assert.deepEqual(account, {
|
||||||
|
|
||||||
// generateAddress return value always includes xAddress to encourage X-address adoption
|
// generateAddress return value always includes xAddress to encourage X-address adoption
|
||||||
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
||||||
|
|
||||||
classicAddress: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7",
|
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||||
address: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7",
|
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE'
|
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async (api) => {
|
'generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1', entropy: new Array(16).fill(0), includeClassicAddress: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ecdsa-secp256k1',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
const account = api.generateAddress(options)
|
const account = api.generateAddress(options)
|
||||||
@@ -129,62 +150,72 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, responses.generateAddress)
|
assert.deepEqual(account, responses.generateAddress)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ed25519` and given entropy; include classic address': async (api) => {
|
'generateAddress with algorithm `ed25519` and given entropy; include classic address': async api => {
|
||||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519', entropy: new Array(16).fill(0), includeClassicAddress: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ed25519',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
const account = api.generateAddress(options)
|
const account = api.generateAddress(options)
|
||||||
|
|
||||||
// THEN we get the expected return value
|
// THEN we get the expected return value
|
||||||
assert.deepEqual(account, {
|
assert.deepEqual(account, {
|
||||||
|
|
||||||
// generateAddress return value always includes xAddress to encourage X-address adoption
|
// generateAddress return value always includes xAddress to encourage X-address adoption
|
||||||
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
||||||
|
|
||||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
||||||
classicAddress: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7",
|
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||||
address: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7"
|
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async (api) => {
|
'generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1', entropy: new Array(16).fill(0), includeClassicAddress: true, test: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ecdsa-secp256k1',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true,
|
||||||
|
test: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
const account = api.generateAddress(options)
|
const account = api.generateAddress(options)
|
||||||
|
|
||||||
// THEN we get the expected return value
|
// THEN we get the expected return value
|
||||||
const response = Object.assign({}, responses.generateAddress, {
|
const response = Object.assign({}, responses.generateAddress, {
|
||||||
|
|
||||||
// generateAddress return value always includes xAddress to encourage X-address adoption
|
// generateAddress return value always includes xAddress to encourage X-address adoption
|
||||||
xAddress: 'TVG3TcCD58BD6MZqsNuTihdrhZwR8SzvYS8U87zvHsAcNw4'
|
xAddress: 'TVG3TcCD58BD6MZqsNuTihdrhZwR8SzvYS8U87zvHsAcNw4'
|
||||||
|
|
||||||
})
|
})
|
||||||
assert.deepEqual(account, response)
|
assert.deepEqual(account, response)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async (api) => {
|
'generateAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async api => {
|
||||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519', entropy: new Array(16).fill(0), includeClassicAddress: true, test: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ed25519',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true,
|
||||||
|
test: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an address
|
// WHEN generating an address
|
||||||
const account = api.generateAddress(options)
|
const account = api.generateAddress(options)
|
||||||
|
|
||||||
// THEN we get the expected return value
|
// THEN we get the expected return value
|
||||||
assert.deepEqual(account, {
|
assert.deepEqual(account, {
|
||||||
|
|
||||||
// generateAddress return value always includes xAddress to encourage X-address adoption
|
// generateAddress return value always includes xAddress to encourage X-address adoption
|
||||||
xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo',
|
xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo',
|
||||||
|
|
||||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
||||||
classicAddress: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7",
|
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||||
address: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7"
|
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateAddress for test network use': async (api) => {
|
'generateAddress for test network use': async api => {
|
||||||
// GIVEN we want an address for test network use
|
// GIVEN we want an address for test network use
|
||||||
const options: GenerateAddressOptions = {test: true}
|
const options: GenerateAddressOptions = {test: true}
|
||||||
|
|
||||||
@@ -194,8 +225,16 @@ export default <TestSuite>{
|
|||||||
// THEN we get an object with xAddress starting with 'T' and a secret starting with 's'
|
// THEN we get an object with xAddress starting with 'T' and a secret starting with 's'
|
||||||
|
|
||||||
// generateAddress return value always includes xAddress to encourage X-address adoption
|
// generateAddress return value always includes xAddress to encourage X-address adoption
|
||||||
assert.deepEqual(account.xAddress.slice(0, 1), 'T', 'Test addresses start with T')
|
assert.deepEqual(
|
||||||
|
account.xAddress.slice(0, 1),
|
||||||
|
'T',
|
||||||
|
'Test addresses start with T'
|
||||||
|
)
|
||||||
|
|
||||||
assert.deepEqual(account.secret.slice(0, 1), 's', `Secret ${account.secret} must start with 's'`)
|
assert.deepEqual(
|
||||||
|
account.secret.slice(0, 1),
|
||||||
|
's',
|
||||||
|
`Secret ${account.secret} must start with 's'`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import assert from 'assert-diff'
|
import assert from 'assert-diff'
|
||||||
import responses from '../../fixtures/responses'
|
import responses from '../../fixtures/responses'
|
||||||
import {TestSuite} from '../../utils'
|
import {TestSuite} from '../../utils'
|
||||||
import { GenerateAddressOptions } from '../../../src/offline/generate-address'
|
import {GenerateAddressOptions} from '../../../src/offline/generate-address'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every test suite exports their tests in the default object.
|
* Every test suite exports their tests in the default object.
|
||||||
@@ -9,7 +9,7 @@ import { GenerateAddressOptions } from '../../../src/offline/generate-address'
|
|||||||
* - Check out "test/api/index.ts" for more information about the test runner.
|
* - Check out "test/api/index.ts" for more information about the test runner.
|
||||||
*/
|
*/
|
||||||
export default <TestSuite>{
|
export default <TestSuite>{
|
||||||
'generateXAddress': async (api) => {
|
'generateXAddress': async api => {
|
||||||
// GIVEN entropy of all zeros
|
// GIVEN entropy of all zeros
|
||||||
function random() {
|
function random() {
|
||||||
return new Array(16).fill(0)
|
return new Array(16).fill(0)
|
||||||
@@ -24,7 +24,7 @@ export default <TestSuite>{
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress invalid entropy': async (api) => {
|
'generateXAddress invalid entropy': async api => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
// GIVEN entropy of 1 byte
|
// GIVEN entropy of 1 byte
|
||||||
function random() {
|
function random() {
|
||||||
@@ -39,18 +39,21 @@ export default <TestSuite>{
|
|||||||
}, api.errors.UnexpectedError)
|
}, api.errors.UnexpectedError)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with no options object': async (api) => {
|
'generateXAddress with no options object': async api => {
|
||||||
// GIVEN no options
|
// GIVEN no options
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress()
|
const account = api.generateXAddress()
|
||||||
|
|
||||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
||||||
assert(account.xAddress.startsWith('X'), 'By default X-addresses start with X')
|
assert(
|
||||||
|
account.xAddress.startsWith('X'),
|
||||||
|
'By default X-addresses start with X'
|
||||||
|
)
|
||||||
assert(account.secret.startsWith('s'), 'Secrets start with s')
|
assert(account.secret.startsWith('s'), 'Secrets start with s')
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with empty options object': async (api) => {
|
'generateXAddress with empty options object': async api => {
|
||||||
// GIVEN an empty options object
|
// GIVEN an empty options object
|
||||||
const options = {}
|
const options = {}
|
||||||
|
|
||||||
@@ -58,11 +61,14 @@ export default <TestSuite>{
|
|||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
|
|
||||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
||||||
assert(account.xAddress.startsWith('X'), 'By default X-addresses start with X')
|
assert(
|
||||||
|
account.xAddress.startsWith('X'),
|
||||||
|
'By default X-addresses start with X'
|
||||||
|
)
|
||||||
assert(account.secret.startsWith('s'), 'Secrets start with s')
|
assert(account.secret.startsWith('s'), 'Secrets start with s')
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ecdsa-secp256k1`': async (api) => {
|
'generateXAddress with algorithm `ecdsa-secp256k1`': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1'
|
// GIVEN we want to use 'ecdsa-secp256k1'
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1'}
|
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1'}
|
||||||
|
|
||||||
@@ -70,12 +76,23 @@ export default <TestSuite>{
|
|||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
|
|
||||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
||||||
assert(account.xAddress.startsWith('X'), 'By default X-addresses start with X')
|
assert(
|
||||||
assert.deepEqual(account.secret.slice(0, 1), 's', `Secret ${account.secret} must start with 's'`)
|
account.xAddress.startsWith('X'),
|
||||||
assert.notStrictEqual(account.secret.slice(0, 3), 'sEd', `secp256k1 secret ${account.secret} must not start with 'sEd'`)
|
'By default X-addresses start with X'
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
account.secret.slice(0, 1),
|
||||||
|
's',
|
||||||
|
`Secret ${account.secret} must start with 's'`
|
||||||
|
)
|
||||||
|
assert.notStrictEqual(
|
||||||
|
account.secret.slice(0, 3),
|
||||||
|
'sEd',
|
||||||
|
`secp256k1 secret ${account.secret} must not start with 'sEd'`
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ed25519`': async (api) => {
|
'generateXAddress with algorithm `ed25519`': async api => {
|
||||||
// GIVEN we want to use 'ed25519'
|
// GIVEN we want to use 'ed25519'
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519'}
|
const options: GenerateAddressOptions = {algorithm: 'ed25519'}
|
||||||
|
|
||||||
@@ -83,13 +100,23 @@ export default <TestSuite>{
|
|||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
|
|
||||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 'sEd'
|
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 'sEd'
|
||||||
assert(account.xAddress.startsWith('X'), 'By default X-addresses start with X')
|
assert(
|
||||||
assert.deepEqual(account.secret.slice(0, 3), 'sEd', `Ed25519 secret ${account.secret} must start with 'sEd'`)
|
account.xAddress.startsWith('X'),
|
||||||
|
'By default X-addresses start with X'
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
account.secret.slice(0, 3),
|
||||||
|
'sEd',
|
||||||
|
`Ed25519 secret ${account.secret} must start with 'sEd'`
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy': async (api) => {
|
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1', entropy: new Array(16).fill(0)}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ecdsa-secp256k1',
|
||||||
|
entropy: new Array(16).fill(0)
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
@@ -98,9 +125,12 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, responses.generateXAddress)
|
assert.deepEqual(account, responses.generateXAddress)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ed25519` and given entropy': async (api) => {
|
'generateXAddress with algorithm `ed25519` and given entropy': async api => {
|
||||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519', entropy: new Array(16).fill(0)}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ed25519',
|
||||||
|
entropy: new Array(16).fill(0)
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
@@ -112,9 +142,13 @@ export default <TestSuite>{
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async (api) => {
|
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1', entropy: new Array(16).fill(0), includeClassicAddress: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ecdsa-secp256k1',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
@@ -123,9 +157,13 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, responses.generateAddress)
|
assert.deepEqual(account, responses.generateAddress)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ed25519` and given entropy; include classic address': async (api) => {
|
'generateXAddress with algorithm `ed25519` and given entropy; include classic address': async api => {
|
||||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519', entropy: new Array(16).fill(0), includeClassicAddress: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ed25519',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
@@ -134,14 +172,19 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, {
|
assert.deepEqual(account, {
|
||||||
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
||||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
||||||
classicAddress: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7",
|
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||||
address: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7"
|
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async (api) => {
|
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async api => {
|
||||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ecdsa-secp256k1', entropy: new Array(16).fill(0), includeClassicAddress: true, test: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ecdsa-secp256k1',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true,
|
||||||
|
test: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
@@ -153,9 +196,14 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, response)
|
assert.deepEqual(account, response)
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async (api) => {
|
'generateXAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async api => {
|
||||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||||
const options: GenerateAddressOptions = {algorithm: 'ed25519', entropy: new Array(16).fill(0), includeClassicAddress: true, test: true}
|
const options: GenerateAddressOptions = {
|
||||||
|
algorithm: 'ed25519',
|
||||||
|
entropy: new Array(16).fill(0),
|
||||||
|
includeClassicAddress: true,
|
||||||
|
test: true
|
||||||
|
}
|
||||||
|
|
||||||
// WHEN generating an X-address
|
// WHEN generating an X-address
|
||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
@@ -164,12 +212,12 @@ export default <TestSuite>{
|
|||||||
assert.deepEqual(account, {
|
assert.deepEqual(account, {
|
||||||
xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo',
|
xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo',
|
||||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
||||||
classicAddress: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7",
|
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||||
address: "r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7"
|
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
'generateXAddress for test network use': async (api) => {
|
'generateXAddress for test network use': async api => {
|
||||||
// GIVEN we want an X-address for test network use
|
// GIVEN we want an X-address for test network use
|
||||||
const options: GenerateAddressOptions = {test: true}
|
const options: GenerateAddressOptions = {test: true}
|
||||||
|
|
||||||
@@ -177,7 +225,15 @@ export default <TestSuite>{
|
|||||||
const account = api.generateXAddress(options)
|
const account = api.generateXAddress(options)
|
||||||
|
|
||||||
// THEN we get an object with xAddress starting with 'T' and a secret starting with 's'
|
// THEN we get an object with xAddress starting with 'T' and a secret starting with 's'
|
||||||
assert.deepEqual(account.xAddress.slice(0, 1), 'T', 'Test X-addresses start with T')
|
assert.deepEqual(
|
||||||
assert.deepEqual(account.secret.slice(0, 1), 's', `Secret ${account.secret} must start with 's'`)
|
account.xAddress.slice(0, 1),
|
||||||
|
'T',
|
||||||
|
'Test X-addresses start with T'
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
account.secret.slice(0, 1),
|
||||||
|
's',
|
||||||
|
`Secret ${account.secret} must start with 's'`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -355,7 +355,8 @@ export default <TestSuite>{
|
|||||||
},
|
},
|
||||||
|
|
||||||
'AccountDelete': async (api, address) => {
|
'AccountDelete': async (api, address) => {
|
||||||
const hash = 'EC2AB14028DC84DE525470AB4DAAA46358B50A8662C63804BFF38244731C0CB9'
|
const hash =
|
||||||
|
'EC2AB14028DC84DE525470AB4DAAA46358B50A8662C63804BFF38244731C0CB9'
|
||||||
const response = await api.getTransaction(hash)
|
const response = await api.getTransaction(hash)
|
||||||
assertResultMatch(
|
assertResultMatch(
|
||||||
response,
|
response,
|
||||||
|
|||||||
@@ -224,26 +224,29 @@ describe('Connection', function() {
|
|||||||
it('DisconnectedError on initial _onOpen send', async function() {
|
it('DisconnectedError on initial _onOpen send', async function() {
|
||||||
// _onOpen previously could throw PromiseRejectionHandledWarning: Promise rejection was handled asynchronously
|
// _onOpen previously could throw PromiseRejectionHandledWarning: Promise rejection was handled asynchronously
|
||||||
// do not rely on the api.setup hook to test this as it bypasses the case, disconnect api connection first
|
// do not rely on the api.setup hook to test this as it bypasses the case, disconnect api connection first
|
||||||
await this.api.disconnect();
|
await this.api.disconnect()
|
||||||
|
|
||||||
// stub _onOpen to only run logic relevant to test case
|
// stub _onOpen to only run logic relevant to test case
|
||||||
this.api.connection._onOpen = () => {
|
this.api.connection._onOpen = () => {
|
||||||
// overload websocket send on open when _ws exists
|
// overload websocket send on open when _ws exists
|
||||||
this.api.connection._ws.send = function(data, options, cb) {
|
this.api.connection._ws.send = function(data, options, cb) {
|
||||||
// recent ws throws this error instead of calling back
|
// recent ws throws this error instead of calling back
|
||||||
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)')
|
||||||
}
|
}
|
||||||
const request = {command: 'subscribe', streams: ['ledger']};
|
const request = {command: 'subscribe', streams: ['ledger']}
|
||||||
return this.api.connection.request(request);
|
return this.api.connection.request(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.api.connect();
|
await this.api.connect()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
assert(error instanceof this.api.errors.DisconnectedError);
|
assert(error instanceof this.api.errors.DisconnectedError)
|
||||||
assert.strictEqual(error.message, 'WebSocket is not open: readyState 0 (CONNECTING)');
|
assert.strictEqual(
|
||||||
|
error.message,
|
||||||
|
'WebSocket is not open: readyState 0 (CONNECTING)'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
it('ResponseFormatError', function() {
|
it('ResponseFormatError', function() {
|
||||||
return this.api
|
return this.api
|
||||||
@@ -380,7 +383,7 @@ describe('Connection', function() {
|
|||||||
}
|
}
|
||||||
// Hook up a listener for the reconnect error event
|
// Hook up a listener for the reconnect error event
|
||||||
this.api.on('error', (error, message) => {
|
this.api.on('error', (error, message) => {
|
||||||
if(error === 'reconnect' && message === 'error on reconnect') {
|
if (error === 'reconnect' && message === 'error on reconnect') {
|
||||||
return done()
|
return done()
|
||||||
}
|
}
|
||||||
return done(new Error('Expected error on reconnect'))
|
return done(new Error('Expected error on reconnect'))
|
||||||
@@ -592,20 +595,20 @@ describe('Connection', function() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
it('should clean up websocket connection if error after websocket is opened', async function() {
|
it('should clean up websocket connection if error after websocket is opened', async function() {
|
||||||
await this.api.disconnect();
|
await this.api.disconnect()
|
||||||
// fail on connection
|
// fail on connection
|
||||||
this.api.connection._subscribeToLedger = async () => {
|
this.api.connection._subscribeToLedger = async () => {
|
||||||
throw new Error('error on _subscribeToLedger')
|
throw new Error('error on _subscribeToLedger')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await this.api.connect();
|
await this.api.connect()
|
||||||
throw new Error('expected connect() to reject, but it resolved')
|
throw new Error('expected connect() to reject, but it resolved')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(err.message === 'error on _subscribeToLedger');
|
assert(err.message === 'error on _subscribeToLedger')
|
||||||
// _ws.close event listener should have cleaned up the socket when disconnect _ws.close is run on connection error
|
// _ws.close event listener should have cleaned up the socket when disconnect _ws.close is run on connection error
|
||||||
// do not fail on connection anymore
|
// do not fail on connection anymore
|
||||||
this.api.connection._subscribeToLedger = async () => {}
|
this.api.connection._subscribeToLedger = async () => {}
|
||||||
await this.api.connection.reconnect();
|
await this.api.connection.reconnect()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user