Skip to content

Commit

Permalink
Merge pull request #18 from Lamden/fix-check-tx-bug
Browse files Browse the repository at this point in the history
now checks if the masternode result is a string
  • Loading branch information
JeffWScott authored Sep 30, 2020
2 parents 620cca2 + 3cf1da1 commit 4019a31
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
27 changes: 18 additions & 9 deletions dist/lamden.js
Original file line number Diff line number Diff line change
Expand Up @@ -5923,20 +5923,29 @@ class TransactionBuilder extends Network {
let checkAgain = false;
const timestamp = new Date().toUTCString();
if (typeof res === 'undefined'){
this.txCheckResult.error = 'TypeError: Failed to fetch';
res = {};
res.error = 'TypeError: Failed to fetch';
}else{
if (res.error){
if (res.error === 'Transaction not found.'){
if (this.txCheckAttempts < this.txCheckLimit){
checkAgain = true;
if (typeof res === 'string') {
if (this.txCheckAttempts < this.txCheckLimit){
checkAgain = true;
}else{
this.txCheckResult.errors = [res];
}
}else{
if (res.error){
if (res.error === 'Transaction not found.'){
if (this.txCheckAttempts < this.txCheckLimit){
checkAgain = true;
}else{
this.txCheckResult.errors = [res.error, `Retry Attmpts ${this.txCheckAttempts} hit while checking for Tx Result.`];
}
}else{
this.txCheckResult.errors = [res.error, `Retry Attmpts ${this.txCheckAttempts} hit while checking for Tx Result.`];
this.txCheckResult.errors = [res.error];
}
}else{
this.txCheckResult.errors = [res.error];
this.txCheckResult = res;
}
}else{
this.txCheckResult = res;
}
}
if (checkAgain) timerId = setTimeout(checkTx.bind(this), 1000);
Expand Down
25 changes: 10 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lamden-js",
"version": "1.20.6",
"version": "1.21.0",
"description": "A javascript implementaion for creating wallets, submitting transactions and interacting with masternodes on the Lamden Blockchain.",
"main": "dist/lamden.js",
"scripts": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"assert": "1.4.1",
"bignumber.js": "^9.0.0",
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.1",
"tweetnacl": "1.0.1",
"types-validate-assert": "^1.0.1"
},
Expand Down
27 changes: 18 additions & 9 deletions src/js/transactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,29 @@ export class TransactionBuilder extends Network {
let checkAgain = false;
const timestamp = new Date().toUTCString();
if (typeof res === 'undefined'){
this.txCheckResult.error = 'TypeError: Failed to fetch'
res = {}
res.error = 'TypeError: Failed to fetch'
}else{
if (res.error){
if (res.error === 'Transaction not found.'){
if (this.txCheckAttempts < this.txCheckLimit){
checkAgain = true
if (typeof res === 'string') {
if (this.txCheckAttempts < this.txCheckLimit){
checkAgain = true
}else{
this.txCheckResult.errors = [res]
}
}else{
if (res.error){
if (res.error === 'Transaction not found.'){
if (this.txCheckAttempts < this.txCheckLimit){
checkAgain = true
}else{
this.txCheckResult.errors = [res.error, `Retry Attmpts ${this.txCheckAttempts} hit while checking for Tx Result.`]
}
}else{
this.txCheckResult.errors = [res.error, `Retry Attmpts ${this.txCheckAttempts} hit while checking for Tx Result.`]
this.txCheckResult.errors = [res.error]
}
}else{
this.txCheckResult.errors = [res.error]
this.txCheckResult = res;
}
}else{
this.txCheckResult = res;
}
}
if (checkAgain) timerId = setTimeout(checkTx.bind(this), 1000);
Expand Down
7 changes: 2 additions & 5 deletions test/masternode_api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,18 @@ describe('Test Masternode API returns', () => {
context('Masternode_API.getCurrencyBalance()', () => {
it('returns the float balance for a vk', async () => {
let response = await goodNetwork_api.getCurrencyBalance(balanceCheckWallet.float)
expect(response.toNumber()).to.be.above(0);
expect(response).to.be.above(0);
})
it('returns the int balance for a vk', async () => {
let response = await goodNetwork_api.getCurrencyBalance(balanceCheckWallet.int)
console.log(response)
expect(response.toFixed(8)).to.be.above(0);
expect(response).to.be.above(0);
})
it('returns 0 if the vk does not exist yet', async () => {
let response = await goodNetwork_api.getCurrencyBalance(wallet.new_wallet().vk)
console.log(response)
expect(response.toNumber()).to.be(0);
})
it('returns 0 if provided network is unresponsive', async () => {
let response = await badNetwork_api.getCurrencyBalance()
console.log(response)
expect(response.toNumber()).to.be(0);
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/transactionBatcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const senderWallet1 = {
sk: "c8a3c5333aa3b058c4fa16d48db52355ab62ddc8daa9a183706a912e522440b6"
}
const senderWallet2 = {
vk: "7d7427785b690cc5d2643d03fc58aedcd9c5574c25a08c03aee88f0e89b6c688",
sk: "1fd04104473c98594dc19ac3a8f370efc3ebe18bf6174a1458176706f148f782"
vk: "6a91a9a65eb80829a360efc0555cad8841af64c78375bbf394f6ecb89d5644ee",
sk: "4166ed44f465c51d562895295cdcde64a3444b14ea2a3e477c60cf0ecde65230"
}

let recieverWallet = {
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Test TransactionBuilder class', () => {
if (!txBuilder.txSendResult.hash) console.log(txBuilder.nonce + ": " + txBuilder.txSendResult.errors)
expect(typeof txBuilder.txSendResult.hash === 'string').to.be(true)
})

console.log(txb)
expect(txb.hasTransactions()).to.be(false)
})
it('Can process overflow', async function () {
Expand Down

0 comments on commit 4019a31

Please sign in to comment.