mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
fix: sequence 0 check, lint and format
This commit is contained in:
@@ -4,10 +4,10 @@ function main() {
|
||||
const servers = ['wss://s1.ripple.com', 'wss://s2.ripple.com']
|
||||
const api = new RippleAPIBroadcast(servers)
|
||||
api.connect().then(() => {
|
||||
api.getServerInfo().then(info => {
|
||||
api.getServerInfo().then((info) => {
|
||||
console.log(JSON.stringify(info, null, 2))
|
||||
})
|
||||
api.on('ledger', ledger => {
|
||||
api.on('ledger', (ledger) => {
|
||||
console.log(JSON.stringify(ledger, null, 2))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,11 +21,11 @@ const request4 = {
|
||||
function makeRequest(connection, request) {
|
||||
return connection
|
||||
.request(request)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
console.log(request)
|
||||
console.log(JSON.stringify(response, null, 2))
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
console.log(request)
|
||||
console.log(error)
|
||||
})
|
||||
@@ -44,7 +44,7 @@ function main() {
|
||||
console.log('Done')
|
||||
})
|
||||
connection.getLedgerVersion().then(console.log)
|
||||
connection.on('ledgerClosed', ledger => {
|
||||
connection.on('ledgerClosed', (ledger) => {
|
||||
console.log(ledger)
|
||||
connection.getLedgerVersion().then(console.log)
|
||||
})
|
||||
|
||||
@@ -22,7 +22,7 @@ function verifyTransaction(testcase, hash, type, options, txData, address) {
|
||||
console.log('VERIFY...')
|
||||
return testcase.api
|
||||
.getTransaction(hash, options)
|
||||
.then(data => {
|
||||
.then((data) => {
|
||||
assert(data && data.outcome)
|
||||
assert.strictEqual(data.type, type)
|
||||
assert.strictEqual(data.address, address)
|
||||
@@ -32,7 +32,7 @@ function verifyTransaction(testcase, hash, type, options, txData, address) {
|
||||
}
|
||||
return {txJSON: JSON.stringify(txData), id: hash, tx: data}
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
if (error instanceof errors.PendingLedgerVersionError) {
|
||||
console.log('NOT VALIDATED YET...')
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -71,12 +71,12 @@ function testTransaction(
|
||||
console.log('PREPARED...')
|
||||
return testcase.api
|
||||
.submit(signedData.signedTransaction)
|
||||
.then(data =>
|
||||
.then((data) =>
|
||||
testcase.test.title.indexOf('multisign') !== -1
|
||||
? acceptLedger(testcase.api).then(() => data)
|
||||
: data
|
||||
)
|
||||
.then(data => {
|
||||
.then((data) => {
|
||||
console.log('SUBMITTED...')
|
||||
assert.strictEqual(data.resultCode, 'tesSUCCESS')
|
||||
const options = {
|
||||
@@ -108,7 +108,7 @@ function setup(this: any, server = 'wss://s1.ripple.com') {
|
||||
() => {
|
||||
console.log('CONNECTED...')
|
||||
},
|
||||
error => {
|
||||
(error) => {
|
||||
console.log('ERROR:', error)
|
||||
throw error
|
||||
}
|
||||
@@ -128,7 +128,7 @@ function makeTrustLine(testcase, address, secret) {
|
||||
}
|
||||
const trust = api
|
||||
.prepareTrustline(address, specification, {})
|
||||
.then(data => {
|
||||
.then((data) => {
|
||||
const signed = api.sign(data.txJSON, secret)
|
||||
if (address === wallet.getAddress()) {
|
||||
testcase.transactions.push(signed.id)
|
||||
@@ -142,8 +142,8 @@ function makeTrustLine(testcase, address, secret) {
|
||||
function makeOrder(api, address, specification, secret) {
|
||||
return api
|
||||
.prepareOrder(address, specification)
|
||||
.then(data => api.sign(data.txJSON, secret))
|
||||
.then(signed => api.submit(signed.signedTransaction))
|
||||
.then((data) => api.sign(data.txJSON, secret))
|
||||
.then((signed) => api.submit(signed.signedTransaction))
|
||||
.then(() => ledgerAccept(api))
|
||||
}
|
||||
|
||||
@@ -158,8 +158,8 @@ function setupAccounts(testcase) {
|
||||
.then(() => {
|
||||
return api
|
||||
.prepareSettings(masterAccount, {defaultRipple: true})
|
||||
.then(data => api.sign(data.txJSON, masterSecret))
|
||||
.then(signed => api.submit(signed.signedTransaction))
|
||||
.then((data) => api.sign(data.txJSON, masterSecret))
|
||||
.then((signed) => api.submit(signed.signedTransaction))
|
||||
.then(() => ledgerAccept(api))
|
||||
})
|
||||
.then(() =>
|
||||
@@ -233,7 +233,7 @@ function suiteSetup(this: any) {
|
||||
// so getLedgerVersion will return right value
|
||||
.then(() => ledgerAccept(this.api))
|
||||
.then(() => this.api.getLedgerVersion())
|
||||
.then(ledgerVersion => {
|
||||
.then((ledgerVersion) => {
|
||||
this.startLedgerVersion = ledgerVersion
|
||||
})
|
||||
.then(() => setupAccounts(this))
|
||||
@@ -241,7 +241,7 @@ function suiteSetup(this: any) {
|
||||
)
|
||||
}
|
||||
|
||||
describe('integration tests', function() {
|
||||
describe('integration tests', function () {
|
||||
const address = wallet.getAddress()
|
||||
const instructions = {maxLedgerVersionOffset: 10}
|
||||
this.timeout(TIMEOUT)
|
||||
@@ -250,31 +250,31 @@ describe('integration tests', function() {
|
||||
beforeEach(_.partial(setup, serverUrl))
|
||||
afterEach(teardown)
|
||||
|
||||
it('settings', function() {
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
it('settings', function () {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
return this.api
|
||||
.prepareSettings(address, requests.prepareSettings.domain, instructions)
|
||||
.then(prepared =>
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'settings', ledgerVersion, prepared)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('trustline', function() {
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
it('trustline', function () {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
return this.api
|
||||
.prepareTrustline(
|
||||
address,
|
||||
requests.prepareTrustline.simple,
|
||||
instructions
|
||||
)
|
||||
.then(prepared =>
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'trustline', ledgerVersion, prepared)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('payment', function() {
|
||||
it('payment', function () {
|
||||
const amount = {currency: 'XRP', value: '0.000001'}
|
||||
const paymentSpecification = {
|
||||
source: {
|
||||
@@ -286,16 +286,16 @@ describe('integration tests', function() {
|
||||
amount: amount
|
||||
}
|
||||
}
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
return this.api
|
||||
.preparePayment(address, paymentSpecification, instructions)
|
||||
.then(prepared =>
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'payment', ledgerVersion, prepared)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('order', function() {
|
||||
it('order', function () {
|
||||
const orderSpecification = {
|
||||
direction: 'buy',
|
||||
quantity: {
|
||||
@@ -308,18 +308,18 @@ describe('integration tests', function() {
|
||||
value: '0.0002'
|
||||
}
|
||||
}
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
return this.api
|
||||
.prepareOrder(address, orderSpecification, instructions)
|
||||
.then(prepared =>
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'order', ledgerVersion, prepared)
|
||||
)
|
||||
.then(result => {
|
||||
.then((result) => {
|
||||
const txData = JSON.parse(result.txJSON)
|
||||
return this.api.getOrders(address).then(orders => {
|
||||
return this.api.getOrders(address).then((orders) => {
|
||||
assert(orders && orders.length > 0)
|
||||
const createdOrder = _.first(
|
||||
_.filter(orders, order => {
|
||||
_.filter(orders, (order) => {
|
||||
return order.properties.sequence === txData.Sequence
|
||||
})
|
||||
)
|
||||
@@ -329,14 +329,14 @@ describe('integration tests', function() {
|
||||
return txData
|
||||
})
|
||||
})
|
||||
.then(txData =>
|
||||
.then((txData) =>
|
||||
this.api
|
||||
.prepareOrderCancellation(
|
||||
address,
|
||||
{orderSequence: txData.Sequence},
|
||||
instructions
|
||||
)
|
||||
.then(prepared =>
|
||||
.then((prepared) =>
|
||||
testTransaction(
|
||||
this,
|
||||
'orderCancellation',
|
||||
@@ -348,56 +348,58 @@ describe('integration tests', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('ticket', function() {
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
it('ticket', function () {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
return this.api
|
||||
.prepareTicket(address, 1, instructions)
|
||||
.then(prepared =>
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'ticket', ledgerVersion, prepared)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('isConnected', function() {
|
||||
it('isConnected', function () {
|
||||
assert(this.api.isConnected())
|
||||
})
|
||||
|
||||
it('getServerInfo', function() {
|
||||
return this.api.getServerInfo().then(data => {
|
||||
it('getServerInfo', function () {
|
||||
return this.api.getServerInfo().then((data) => {
|
||||
assert(data && data.pubkeyNode)
|
||||
})
|
||||
})
|
||||
|
||||
it('getFee', function() {
|
||||
return this.api.getFee().then(fee => {
|
||||
it('getFee', function () {
|
||||
return this.api.getFee().then((fee) => {
|
||||
assert.strictEqual(typeof fee, 'string')
|
||||
assert(!isNaN(Number(fee)))
|
||||
assert(parseFloat(fee) === Number(fee))
|
||||
})
|
||||
})
|
||||
|
||||
it('getLedgerVersion', function() {
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
it('getLedgerVersion', function () {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
assert.strictEqual(typeof ledgerVersion, 'number')
|
||||
assert(ledgerVersion >= this.startLedgerVersion)
|
||||
})
|
||||
})
|
||||
|
||||
it('getTransactions', function() {
|
||||
it('getTransactions', function () {
|
||||
const options = {
|
||||
initiated: true,
|
||||
minLedgerVersion: this.startLedgerVersion
|
||||
}
|
||||
return this.api.getTransactions(address, options).then(transactionsData => {
|
||||
assert(transactionsData)
|
||||
assert.strictEqual(transactionsData.length, this.transactions.length)
|
||||
})
|
||||
return this.api
|
||||
.getTransactions(address, options)
|
||||
.then((transactionsData) => {
|
||||
assert(transactionsData)
|
||||
assert.strictEqual(transactionsData.length, this.transactions.length)
|
||||
})
|
||||
})
|
||||
|
||||
it('getTrustlines', function() {
|
||||
it('getTrustlines', function () {
|
||||
const fixture = requests.prepareTrustline.simple
|
||||
const options = _.pick(fixture, ['currency', 'counterparty'])
|
||||
return this.api.getTrustlines(address, options).then(data => {
|
||||
return this.api.getTrustlines(address, options).then((data) => {
|
||||
assert(data && data.length > 0 && data[0] && data[0].specification)
|
||||
const specification = data[0].specification
|
||||
assert.strictEqual(Number(specification.limit), Number(fixture.limit))
|
||||
@@ -406,24 +408,24 @@ describe('integration tests', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('getBalances', function() {
|
||||
it('getBalances', function () {
|
||||
const fixture = requests.prepareTrustline.simple
|
||||
const options = _.pick(fixture, ['currency', 'counterparty'])
|
||||
return this.api.getBalances(address, options).then(data => {
|
||||
return this.api.getBalances(address, options).then((data) => {
|
||||
assert(data && data.length > 0 && data[0])
|
||||
assert.strictEqual(data[0].currency, fixture.currency)
|
||||
assert.strictEqual(data[0].counterparty, fixture.counterparty)
|
||||
})
|
||||
})
|
||||
|
||||
it('getSettings', function() {
|
||||
return this.api.getSettings(address).then(data => {
|
||||
it('getSettings', function () {
|
||||
return this.api.getSettings(address).then((data) => {
|
||||
assert(data)
|
||||
assert.strictEqual(data.domain, requests.prepareSettings.domain.domain)
|
||||
})
|
||||
})
|
||||
|
||||
it('getOrderbook', function() {
|
||||
it('getOrderbook', function () {
|
||||
const orderbook = {
|
||||
base: {
|
||||
currency: 'XRP'
|
||||
@@ -433,7 +435,7 @@ describe('integration tests', function() {
|
||||
counterparty: masterAccount
|
||||
}
|
||||
}
|
||||
return this.api.getOrderbook(address, orderbook).then(book => {
|
||||
return this.api.getOrderbook(address, orderbook).then((book) => {
|
||||
assert(book && book.bids && book.bids.length > 0)
|
||||
assert(book.asks && book.asks.length > 0)
|
||||
const bid = book.bids[0]
|
||||
@@ -451,7 +453,7 @@ describe('integration tests', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('getPaths', function() {
|
||||
it('getPaths', function () {
|
||||
const pathfind = {
|
||||
source: {
|
||||
address: address
|
||||
@@ -465,7 +467,7 @@ describe('integration tests', function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.api.getPaths(pathfind).then(data => {
|
||||
return this.api.getPaths(pathfind).then((data) => {
|
||||
assert(data && data.length > 0)
|
||||
const path = data[0]
|
||||
assert(path && path.source)
|
||||
@@ -474,7 +476,7 @@ describe('integration tests', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('getPaths - send all', function() {
|
||||
it('getPaths - send all', function () {
|
||||
const pathfind = {
|
||||
source: {
|
||||
address: address,
|
||||
@@ -491,10 +493,10 @@ describe('integration tests', function() {
|
||||
}
|
||||
}
|
||||
|
||||
return this.api.getPaths(pathfind).then(data => {
|
||||
return this.api.getPaths(pathfind).then((data) => {
|
||||
assert(data && data.length > 0)
|
||||
assert(
|
||||
_.every(data, path => {
|
||||
_.every(data, (path) => {
|
||||
return (
|
||||
parseFloat(path.source.amount.value) <=
|
||||
parseFloat(pathfind.source.amount.value)
|
||||
@@ -508,7 +510,7 @@ describe('integration tests', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('generateWallet', function() {
|
||||
it('generateWallet', function () {
|
||||
const newWallet = this.api.generateAddress()
|
||||
assert(newWallet && newWallet.address && newWallet.secret)
|
||||
assert(isValidAddress(newWallet.address))
|
||||
@@ -516,7 +518,7 @@ describe('integration tests', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('integration tests - standalone rippled', function() {
|
||||
describe('integration tests - standalone rippled', function () {
|
||||
const instructions = {maxLedgerVersionOffset: 10}
|
||||
this.timeout(TIMEOUT)
|
||||
|
||||
@@ -529,7 +531,7 @@ describe('integration tests - standalone rippled', function() {
|
||||
const signer2address = 'r3RtUvGw9nMoJ5FuHxuoVJvcENhKtuF9ud'
|
||||
const signer2secret = 'shUHQnL4EH27V4EiBrj6EfhWvZngF'
|
||||
|
||||
it('submit multisigned transaction', function() {
|
||||
it('submit multisigned transaction', function () {
|
||||
const signers = {
|
||||
threshold: 2,
|
||||
weights: [
|
||||
@@ -540,11 +542,11 @@ describe('integration tests - standalone rippled', function() {
|
||||
let minLedgerVersion = null
|
||||
return payTo(this.api, address)
|
||||
.then(() => {
|
||||
return this.api.getLedgerVersion().then(ledgerVersion => {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
minLedgerVersion = ledgerVersion
|
||||
return this.api
|
||||
.prepareSettings(address, {signers}, instructions)
|
||||
.then(prepared => {
|
||||
.then((prepared) => {
|
||||
return testTransaction(
|
||||
this,
|
||||
'settings',
|
||||
@@ -566,7 +568,7 @@ describe('integration tests - standalone rippled', function() {
|
||||
{domain: 'example.com'},
|
||||
multisignInstructions
|
||||
)
|
||||
.then(prepared => {
|
||||
.then((prepared) => {
|
||||
const signed1 = this.api.sign(prepared.txJSON, signer1secret, {
|
||||
signAs: signer1address
|
||||
})
|
||||
@@ -579,8 +581,8 @@ describe('integration tests - standalone rippled', function() {
|
||||
])
|
||||
return this.api
|
||||
.submit(combined.signedTransaction)
|
||||
.then(response => acceptLedger(this.api).then(() => response))
|
||||
.then(response => {
|
||||
.then((response) => acceptLedger(this.api).then(() => response))
|
||||
.then((response) => {
|
||||
assert.strictEqual(response.resultCode, 'tesSUCCESS')
|
||||
const options = {minLedgerVersion}
|
||||
return verifyTransaction(
|
||||
@@ -592,7 +594,7 @@ describe('integration tests - standalone rippled', function() {
|
||||
address
|
||||
)
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
console.log(error.message)
|
||||
throw error
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user