mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 01:02:00 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac83827fca | ||
|
|
0811024030 | ||
|
|
737d35463d | ||
|
|
2ed1eaba9c | ||
|
|
6dddfbdcb6 | ||
|
|
fc2d7b4b9b | ||
|
|
9681def3e0 | ||
|
|
42f228af0e | ||
|
|
4ac7f59378 | ||
|
|
725c1c39a5 | ||
|
|
7290c8db30 | ||
|
|
36e1ec1f8e | ||
|
|
baa574a93e | ||
|
|
8333563d98 | ||
|
|
99fd116b6d | ||
|
|
ccae89ad01 | ||
|
|
0ecae58be2 | ||
|
|
5f442835e5 | ||
|
|
aa8fd89227 | ||
|
|
3da7432273 | ||
|
|
61c1dd5878 | ||
|
|
c095e7af39 | ||
|
|
fb9612bb65 | ||
|
|
e4a37b1c10 | ||
|
|
ba4f847e57 | ||
|
|
81e623e35f | ||
|
|
db1da9172c |
@@ -53,7 +53,7 @@ RUN git clone https://github.com/Permissionless-Software-Foundation/bch-dex-ui-v
|
||||
WORKDIR /home/safeuser/bch-dex-ui-v3
|
||||
|
||||
# For development: switch to unstable branch
|
||||
RUN git checkout ct-unstable
|
||||
RUN git checkout psfoundation
|
||||
|
||||
# Install dependencies
|
||||
#RUN mkdir .ipfsdata
|
||||
|
||||
@@ -31,4 +31,7 @@ export APP_ID=bch-dex-001
|
||||
|
||||
#export P2WDB_URL=http://172.17.0.1:5667
|
||||
|
||||
export DISABLE_NEW_ACCOUNTS=true
|
||||
export ADMIN_PASSWORD=decatur
|
||||
|
||||
npm start
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"privateKey": "L4VyBDiWYYeeZhkM3xE3nsZigXJYmvRM29YBxoC7da4FzvubjxFo",
|
||||
"publicKey": "028d6c77d865e6140db4b879a9bdf69ee4846593c0b6c48a82c448d5792806aab1",
|
||||
"mnemonic": "split title trigger soda execute frost brush labor vague protect bicycle fiscal",
|
||||
"cashAddress": "bitcoincash:qprrdk7en7m774gsafkycxcymc9ry209jus5v8wx5z",
|
||||
"address": "bitcoincash:qprrdk7en7m774gsafkycxcymc9ry209jus5v8wx5z",
|
||||
"legacyAddress": "17QG25rNUfnfj2NtdaFiyiqKSJatvEnMYd",
|
||||
"hdPath": "m/44'/245'/0'/0/0",
|
||||
"slpAddress": "simpleledger:qprrdk7en7m774gsafkycxcymc9ry209juu08umx2u",
|
||||
"nextAddress": 1
|
||||
}
|
||||
@@ -4,8 +4,11 @@ const CounterOffer = new mongoose.Schema({
|
||||
nostrEventId: { type: String, required: true }, // Nostr Event Id.
|
||||
takerAddr: { type: String, default: null },
|
||||
takerNpub: { type: String, default: null },
|
||||
makerNpub: { type: String, default: null },
|
||||
counterOfferAddr: { type: String, default: null },
|
||||
counterOfferUtxo: { type: String, default: null }
|
||||
counterOfferUtxo: { type: String, default: null },
|
||||
takerOfferUtxo: { type: String, default: null },
|
||||
tokenId: { type: String, default: null }
|
||||
})
|
||||
|
||||
export default mongoose.model('counterOffer', CounterOffer)
|
||||
|
||||
@@ -46,6 +46,7 @@ const Offer = new mongoose.Schema({
|
||||
immutableDataCid: { type: String, default: null },
|
||||
mutableDataCid: { type: String, default: null },
|
||||
tokenIconUrl: { type: String, default: null },
|
||||
tokenData: { type: Object },
|
||||
tokenCategories: { type: Array, default: [] },
|
||||
tokenTags: { type: Array, default: [] },
|
||||
userDataStr: { type: String }, // Token user data
|
||||
|
||||
@@ -16,8 +16,11 @@ class CounterOfferEntity {
|
||||
nostrEventId,
|
||||
takerAddr,
|
||||
takerNpub,
|
||||
makerNpub,
|
||||
counterOfferAddr,
|
||||
counterOfferUtxo
|
||||
counterOfferUtxo,
|
||||
takerOfferUtxo,
|
||||
tokenId
|
||||
} = offerData.data
|
||||
|
||||
// Input Validation
|
||||
@@ -37,13 +40,25 @@ class CounterOfferEntity {
|
||||
if (counterOfferUtxo && typeof counterOfferUtxo !== 'string') {
|
||||
throw new Error("Property 'counterOfferUtxo' must be a string.")
|
||||
}
|
||||
if (takerOfferUtxo && typeof takerOfferUtxo !== 'string') {
|
||||
throw new Error("Property 'takerOfferUtxo' must be a string.")
|
||||
}
|
||||
if (tokenId && typeof tokenId !== 'string') {
|
||||
throw new Error("Property 'tokenId' must be a string.")
|
||||
}
|
||||
if (makerNpub && typeof makerNpub !== 'string') {
|
||||
throw new Error("Property 'makerNpub' must be a string.")
|
||||
}
|
||||
|
||||
const validatedCounterOfferData = {
|
||||
nostrEventId,
|
||||
takerAddr,
|
||||
takerNpub,
|
||||
counterOfferAddr,
|
||||
counterOfferUtxo
|
||||
counterOfferUtxo,
|
||||
takerOfferUtxo,
|
||||
tokenId,
|
||||
makerNpub
|
||||
}
|
||||
|
||||
return validatedCounterOfferData
|
||||
|
||||
@@ -148,6 +148,7 @@ class OfferUseCases {
|
||||
const immutableDataCid = tokenData.immutableData
|
||||
offerEntity.mutableDataCid = mutableDataCid
|
||||
offerEntity.immutableDataCid = immutableDataCid
|
||||
offerEntity.tokenData = tokenData
|
||||
|
||||
// Get the mutable data from the cid if it exists.
|
||||
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
||||
@@ -608,6 +609,8 @@ class OfferUseCases {
|
||||
// Create counter offer entity for nostr event id if it not exist
|
||||
const existingCounterOffer = await this.CounterOfferModel.findOne(({ nostrEventId: eventId }))
|
||||
if (!existingCounterOffer) {
|
||||
// Add taker offer utxo to counter offer data.
|
||||
offerData.data.takerOfferUtxo = offerData.data.utxoTxid
|
||||
const counterOEntity = this.counterOfferEntity.validate(offerData)
|
||||
// Create new counter offfer model and save it.
|
||||
const counterOffer = new this.CounterOfferModel(counterOEntity)
|
||||
@@ -998,6 +1001,7 @@ class OfferUseCases {
|
||||
const immutableDataCid = tokenData.immutableData
|
||||
offer.mutableDataCid = mutableDataCid
|
||||
offer.immutableDataCid = immutableDataCid
|
||||
offer.tokenData = tokenData
|
||||
|
||||
// Get the mutable data from the cid if it exists.
|
||||
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
||||
|
||||
@@ -11,7 +11,7 @@ let sandbox
|
||||
let uut
|
||||
|
||||
describe('#CounterOffer-Entity', () => {
|
||||
before(async () => {})
|
||||
before(async () => { })
|
||||
|
||||
beforeEach(() => {
|
||||
uut = new CounterOfferEntity()
|
||||
@@ -24,7 +24,7 @@ describe('#CounterOffer-Entity', () => {
|
||||
describe('#validate', () => {
|
||||
it('should throw an error if data is not provided', () => {
|
||||
try {
|
||||
uut.validate({ })
|
||||
uut.validate({})
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Input to counterOffer.validate() must be an object with a data property.')
|
||||
}
|
||||
@@ -59,12 +59,26 @@ describe('#CounterOffer-Entity', () => {
|
||||
assert.include(err.message, "Property 'takerNpub' must be a string")
|
||||
}
|
||||
})
|
||||
it('should throw an error if provided makerNpub is not string', () => {
|
||||
try {
|
||||
const inObj = {
|
||||
nostrEventId: 'nostr event id',
|
||||
takerAddr: 'taker address',
|
||||
takerNpub: 'npub',
|
||||
makerNpub: 1234
|
||||
}
|
||||
uut.validate({ data: inObj })
|
||||
} catch (err) {
|
||||
assert.include(err.message, "Property 'makerNpub' must be a string")
|
||||
}
|
||||
})
|
||||
it('should throw an error if provided counterOfferAddr is not string', () => {
|
||||
try {
|
||||
const inObj = {
|
||||
nostrEventId: 'nostr event id',
|
||||
takerAddr: 'taker address',
|
||||
takerNpub: 'npub',
|
||||
makerNpub: 'npub',
|
||||
counterOfferAddr: 1234
|
||||
}
|
||||
uut.validate({ data: inObj })
|
||||
@@ -78,6 +92,7 @@ describe('#CounterOffer-Entity', () => {
|
||||
nostrEventId: 'nostr event id',
|
||||
takerAddr: 'taker address',
|
||||
takerNpub: 'npub',
|
||||
makerNpub: 'npub',
|
||||
counterOfferAddr: 'counter offer address',
|
||||
counterOfferUtxo: 1234
|
||||
}
|
||||
@@ -86,13 +101,50 @@ describe('#CounterOffer-Entity', () => {
|
||||
assert.include(err.message, "Property 'counterOfferUtxo' must be a string")
|
||||
}
|
||||
})
|
||||
it('should throw an error if provided takerOfferUtxo is not string', () => {
|
||||
try {
|
||||
const inObj = {
|
||||
nostrEventId: 'nostr event id',
|
||||
takerAddr: 'taker address',
|
||||
takerNpub: 'npub',
|
||||
makerNpub: 'npub',
|
||||
counterOfferAddr: 'counter offer address',
|
||||
counterOfferUtxo: 'utxo txid',
|
||||
takerOfferUtxo: 1234
|
||||
}
|
||||
uut.validate({ data: inObj })
|
||||
} catch (err) {
|
||||
assert.include(err.message, "Property 'takerOfferUtxo' must be a string")
|
||||
}
|
||||
})
|
||||
it('should throw an error if provided tokenId is not string', () => {
|
||||
try {
|
||||
const inObj = {
|
||||
nostrEventId: 'nostr event id',
|
||||
takerAddr: 'taker address',
|
||||
takerNpub: 'npub',
|
||||
makerNpub: 'npub',
|
||||
counterOfferAddr: 'counter offer address',
|
||||
counterOfferUtxo: 'utxo txid',
|
||||
takerOfferUtxo: 'utxo txid',
|
||||
tokenId: 1234
|
||||
}
|
||||
uut.validate({ data: inObj })
|
||||
} catch (err) {
|
||||
assert.include(err.message, "Property 'tokenId' must be a string")
|
||||
}
|
||||
})
|
||||
|
||||
it('should return a counter offer object', () => {
|
||||
const inObj = {
|
||||
nostrEventId: 'nostr event id',
|
||||
takerAddr: 'taker address',
|
||||
takerNpub: 'npub',
|
||||
makerNpub: 'npub',
|
||||
counterOfferAddr: 'counter offer address',
|
||||
counterOfferUtxo: 'utxo txid'
|
||||
counterOfferUtxo: 'utxo txid',
|
||||
takerOfferUtxo: 'utxo txid',
|
||||
tokenId: 'token id'
|
||||
}
|
||||
|
||||
const counterOfferEntity = uut.validate({ data: inObj })
|
||||
@@ -106,11 +158,20 @@ describe('#CounterOffer-Entity', () => {
|
||||
assert.property(counterOfferEntity, 'takerNpub')
|
||||
assert.equal(counterOfferEntity.takerNpub, inObj.takerNpub)
|
||||
|
||||
assert.property(counterOfferEntity, 'makerNpub')
|
||||
assert.equal(counterOfferEntity.makerNpub, inObj.makerNpub)
|
||||
|
||||
assert.property(counterOfferEntity, 'counterOfferAddr')
|
||||
assert.equal(counterOfferEntity.counterOfferAddr, inObj.counterOfferAddr)
|
||||
|
||||
assert.property(counterOfferEntity, 'counterOfferUtxo')
|
||||
assert.equal(counterOfferEntity.counterOfferUtxo, inObj.counterOfferUtxo)
|
||||
|
||||
assert.property(counterOfferEntity, 'takerOfferUtxo')
|
||||
assert.equal(counterOfferEntity.takerOfferUtxo, inObj.takerOfferUtxo)
|
||||
|
||||
assert.property(counterOfferEntity, 'tokenId')
|
||||
assert.equal(counterOfferEntity.tokenId, inObj.tokenId)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -107,14 +107,14 @@ describe('#offer-use-case', () => {
|
||||
const result = await uut.createOffer(offerObj)
|
||||
assert.isFalse(result)
|
||||
})
|
||||
|
||||
it('should create offer with mutable data', async () => {
|
||||
it('should create offer with token data', async () => {
|
||||
const tokenDataMock = mockData.nftTokenData01
|
||||
const offerObj = mockData.offerMockData
|
||||
const mutableDataMock = mockData.mutableDataMock
|
||||
const offerEntityMock = Object.assign({}, mockData.offerMockData.data)
|
||||
|
||||
// Mock dependencies
|
||||
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
|
||||
sandbox.stub(uut.offerEntity, 'validate').returns(offerEntityMock)
|
||||
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).resolves({}) // Utxo Status call
|
||||
@@ -123,6 +123,31 @@ describe('#offer-use-case', () => {
|
||||
|
||||
const result = await uut.createOffer(offerObj)
|
||||
assert.isTrue(result)
|
||||
console.log('offerEntityMock', offerEntityMock)
|
||||
assert.property(offerEntityMock, 'tokenData')
|
||||
})
|
||||
it('should create offer with mutable data', async () => {
|
||||
const tokenDataMock = mockData.nftTokenData01
|
||||
const offerObj = mockData.offerMockData
|
||||
const mutableDataMock = mockData.mutableDataMock
|
||||
const offerEntityMock = Object.assign({}, mockData.offerMockData.data)
|
||||
|
||||
// Mock dependencies
|
||||
sandbox.stub(uut.offerEntity, 'validate').returns(offerEntityMock)
|
||||
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).resolves({}) // Utxo Status call
|
||||
.onCall(1).resolves(tokenDataMock) // Token Data call
|
||||
.onCall(2).resolves(mutableDataMock)
|
||||
|
||||
const result = await uut.createOffer(offerObj)
|
||||
assert.isTrue(result)
|
||||
console.log('offerEntityMock', offerEntityMock)
|
||||
|
||||
assert.property(offerEntityMock, 'tokenIconUrl')
|
||||
assert.property(offerEntityMock, 'tokenCategories')
|
||||
assert.property(offerEntityMock, 'tokenTags')
|
||||
assert.property(offerEntityMock, 'lastUpdatedTokenData')
|
||||
})
|
||||
|
||||
it('should skip userData stringify error', async () => {
|
||||
@@ -1106,6 +1131,12 @@ describe('#offer-use-case', () => {
|
||||
const offer = await uut.syncOfferMutableData('tokenId')
|
||||
assert.isObject(offer)
|
||||
assert.isNumber(offer.lastUpdatedTokenData)
|
||||
|
||||
assert.property(offer, 'tokenData')
|
||||
assert.property(offer, 'tokenIconUrl')
|
||||
assert.property(offer, 'tokenCategories')
|
||||
assert.property(offer, 'tokenTags')
|
||||
assert.property(offer, 'lastUpdatedTokenData')
|
||||
})
|
||||
|
||||
it('should skip userData stringify error', async () => {
|
||||
|
||||
@@ -11,12 +11,12 @@ import axios from 'axios'
|
||||
// import User from '../../../src/adapters/localdb/models/users.js'
|
||||
|
||||
// Customize these variables
|
||||
const EMAIL = 'someone@somewhere.com'
|
||||
const NAME = 'Someone'
|
||||
const PASSWORD = 'test'
|
||||
const EMAIL = 'chris.troutner@gmail.com'
|
||||
const NAME = 'Chris'
|
||||
const PASSWORD = '0mega16'
|
||||
|
||||
const ADMIN_EMAIL = 'system@system.com'
|
||||
const ADMIN_PASSWORD = 'admin'
|
||||
const ADMIN_PASSWORD = 'decatur'
|
||||
|
||||
async function createUser () {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user