fix(e2e): Got e2e create-offer.js working

This commit is contained in:
Chris Troutner
2022-02-23 14:03:57 -08:00
parent 956c67a288
commit f4a1f77077
7 changed files with 223 additions and 346 deletions
+1
View File
@@ -78,6 +78,7 @@ module.exports = {
},
// P2WDB webhook endpoint
p2wdbPort: process.env.P2WDB_PORT ? process.env.P2WDB_PORT : 5010,
webhookService: process.env.WEBHOOKSERVICE
? process.env.WEBHOOKSERVICE
: 'http://localhost:5010/webhook', // P2WDB.
+206 -339
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -51,7 +51,7 @@
"koa2-ratelimit": "0.9.1",
"libp2p": "^0.36.2",
"line-reader": "0.4.0",
"minimal-slp-wallet": "4.4.1",
"minimal-slp-wallet": "../minimal-slp-wallet",
"mongoose": "5.13.13",
"node-fetch": "npm:@achingbrain/node-fetch@2.6.7",
"nodemailer": "6.4.17",
+7 -1
View File
@@ -5,14 +5,20 @@
// Public npm libraries.
const axios = require('axios')
// Local libraries
const config = require('../../config')
// Global constants
const P2WDB_SERVER = 'http://localhost:5001/entry/write'
let P2WDB_SERVER = 'http://localhost:5001/entry/write'
// const P2WDB_SERVER = 'https://p2wdb.fullstack.cash/entry/write'
class P2wdbAdapter {
constructor (localConfig = {}) {
// Encapsulate dependencies
this.axios = axios
this.config = config
P2WDB_SERVER = `http://localhost:${config.p2wdbPort}/entry/write`
}
async write (inputObj) {
+5 -3
View File
@@ -36,7 +36,6 @@ class WalletAdapter {
walletData = await this.jsonFiles.readJSON(this.WALLET_FILE)
} catch (err) {
// Create a new wallet file if one does not already exist.
// console.log('caught: ', err)
console.warn('Wallet file not found. Creating new wallet.json file.')
// Create a new wallet.
@@ -140,7 +139,7 @@ class WalletAdapter {
const childNode = masterHDNode.derivePath(`m/44'/245'/0'/0/${hdIndex}`)
const cashAddress = this.bchWallet.bchjs.HDNode.toCashAddress(childNode)
console.log('cashAddress: ', cashAddress)
console.log('Generating a new key pair for cashAddress: ', cashAddress)
const wif = this.bchWallet.bchjs.HDNode.toWIF(childNode)
@@ -195,6 +194,7 @@ class WalletAdapter {
// Get token UTXOs held by the wallet.
const tokenUtxos = this.bchWallet.utxos.utxoStore.slpUtxos.type1.tokens
console.log(`tokenUtxos: ${JSON.stringify(tokenUtxos, null, 2)}`)
// Find a token UTXO that contains PSF with a quantity higher than needed
// to generate a proof-of-burn.
@@ -204,7 +204,7 @@ class WalletAdapter {
// If token ID matches.
if (thisUtxo.tokenId === P2WDB_TOKEN_ID) {
if (parseFloat(thisUtxo.tokenQty) >= PROOF_OF_BURN_QTY) {
if (parseFloat(thisUtxo.qtyStr) >= PROOF_OF_BURN_QTY) {
tokenUtxo = thisUtxo
break
}
@@ -217,6 +217,8 @@ class WalletAdapter {
)
}
console.log(`tokenUtxo: ${JSON.stringify(tokenUtxo, null, 2)}`)
const result = await this.bchWallet.burnTokens(
PROOF_OF_BURN_QTY,
P2WDB_TOKEN_ID
+2 -1
View File
@@ -49,7 +49,8 @@ class OfferRESTControllerLib {
// DRY error handler
handleError (ctx, err) {
console.log('err', err.message)
console.log('err', err)
// If an HTTP status is specified by the buisiness logic, use that.
if (err.status) {
if (err.message) {
+1 -1
View File
@@ -25,7 +25,7 @@ class OfferLib {
// Input Validation
const offerEntity = this.offerEntity.validate(entryObj)
// console.log('offerEntity: ', offerEntity)
console.log('offerEntity: ', offerEntity)
// Ensure sufficient tokens exist to create the offer.
await this.ensureFunds(offerEntity)