diff --git a/src/use-cases/offer.js b/src/use-cases/offer.js index 2f6283f..fcb2be5 100644 --- a/src/use-cases/offer.js +++ b/src/use-cases/offer.js @@ -27,10 +27,24 @@ class OfferLib { console.log('offerEntity: ', offerEntity) // Verify that the entry was signed by a specific BCH address. - const isValidSignature = this.bch._verifySignature(offerEntity) - if (!isValidSignature) { - throw new Error('Invalid signature') + // const isValidSignature = this.bch._verifySignature(offerEntity) + // if (!isValidSignature) { + // throw new Error('Invalid signature') + // } + + // generate signature. + const now = new Date() + const message = now.toISOString() + const signature = await this.adapters.wallet.generateSignature(message) + console.log('signature: ', signature) + + // Burn PSF token to pay for P2WDB write. + const result = await await this.adapters.wallet.burnPsf() + if (!result.success) { + throw new Error('Could not burn PSF token to pay for P2WDB write.') } + const txid = result.txid + console.log('txid: ', txid) // Add offer to P2WDB. diff --git a/test/e2e/automated/a10-offer.rest-e2e.js b/test/e2e/automated/a10-offer.rest-e2e.js index fe72d3d..39a8e5a 100644 --- a/test/e2e/automated/a10-offer.rest-e2e.js +++ b/test/e2e/automated/a10-offer.rest-e2e.js @@ -2,13 +2,13 @@ Automated E2E tests for the /offer endpoint. */ -const config = require('../../../config') -const assert = require('chai').assert +// const config = require('../../../config') +// const assert = require('chai').assert -const axios = require('axios').default +// const axios = require('axios').default const sinon = require('sinon') -const LOCALHOST = `http://localhost:${config.port}` +// const LOCALHOST = `http://localhost:${config.port}` // const OfferController = require('../../../src/controllers/rest-api/offer/controller') // const mockContext = require('../../unit/mocks/ctx-mock').context @@ -25,40 +25,40 @@ describe('OfferApi', () => { afterEach(() => sandbox.restore()) describe('POST /offer', () => { - it('should pass data to the handlers', async () => { - try { - const mockOffer = { - lokadId: 'SWP', - messageType: 1, - messageClass: 1, - tokenId: 'token-id', - buyOrSell: 'sell', - rateInSats: 1000, - minSatsToExchange: 1250, - signature: - 'H4cRPaAtyNyzG+4Qz+Tp2O7TtFZ7QRsWKKxG71dUZG5xfX0EWRMrBmqM6rH7jToOAT2s9Dm759HMxwP/WTMPzyA=', - sigMsg: 'test', - utxoTxid: 'txid-goes-here', - utxoVout: 1, - offerIpfsId: 'Qmblah', - offerBchAddr: - 'bitcoincash:qzxj37k35z6whp4mj4hrdw2vprx4klcydc6ete5xft', - offerPubKey: 'pubkeyInHex' - } - - const options = { - method: 'post', - url: `${LOCALHOST}/offer`, - data: { offer: mockOffer } - } - - const result = await axios(options) - console.log('result.data: ', result.data) - - // assert.isFalse(result.data.success) - } catch (err) { - assert(false, 'Unexpected result') - } - }) + // it('should pass data to the handlers', async () => { + // try { + // const mockOffer = { + // lokadId: 'SWP', + // messageType: 1, + // messageClass: 1, + // tokenId: 'token-id', + // buyOrSell: 'sell', + // rateInSats: 1000, + // minSatsToExchange: 1250, + // signature: + // 'H4cRPaAtyNyzG+4Qz+Tp2O7TtFZ7QRsWKKxG71dUZG5xfX0EWRMrBmqM6rH7jToOAT2s9Dm759HMxwP/WTMPzyA=', + // sigMsg: 'test', + // utxoTxid: 'txid-goes-here', + // utxoVout: 1, + // offerIpfsId: 'Qmblah', + // offerBchAddr: + // 'bitcoincash:qzxj37k35z6whp4mj4hrdw2vprx4klcydc6ete5xft', + // offerPubKey: 'pubkeyInHex' + // } + // + // const options = { + // method: 'post', + // url: `${LOCALHOST}/offer`, + // data: { offer: mockOffer } + // } + // + // const result = await axios(options) + // console.log('result.data: ', result.data) + // + // // assert.isFalse(result.data.success) + // } catch (err) { + // assert(false, 'Unexpected result') + // } + // }) }) }) diff --git a/test/e2e/manual/create-offer.js b/test/e2e/manual/create-offer.js new file mode 100644 index 0000000..d1a3038 --- /dev/null +++ b/test/e2e/manual/create-offer.js @@ -0,0 +1,37 @@ +/* + A manual test for creating an swap offer. + + Ensure the REST API is up an running before running this test. +*/ + +const axios = require('axios') + +const LOCALHOST = 'http://localhost:5700' + +async function start () { + try { + const mockOffer = { + lokadId: 'SWP', + messageType: 1, + messageClass: 1, + tokenId: 'token-id', + buyOrSell: 'sell', + rateInSats: 1000, + minSatsToExchange: 1250, + utxoTxid: 'txid-goes-here', + utxoVout: 1 + } + + const options = { + method: 'post', + url: `${LOCALHOST}/offer`, + data: { offer: mockOffer } + } + + const result = await axios(options) + console.log('result.data: ', result.data) + } catch (err) { + console.log(err) + } +} +start()