fix(moveTokens): Moved from order use-case to wallet adapter

This commit is contained in:
Chris Troutner
2022-03-21 14:03:40 -07:00
parent 8ed1dbcffe
commit 810d386dbc
8 changed files with 177 additions and 104 deletions
@@ -38,4 +38,27 @@ describe('#wallet', () => {
assert.equal(walletInstance.ar.interface, 'rest-api')
})
})
describe('#moveTokens', () => {
it('should move tokens to a new address in the HD wallet', async () => {
const walletData = await uut.openWallet()
// Force usage of FullStack.cash
uut.config.useFullStackCash = true
await uut.instanceWallet(walletData)
const inObj = {
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
qty: 1
}
const result = await uut.moveTokens(inObj)
// console.log('result: ', result)
assert.property(result, 'txid')
assert.property(result, 'vout')
assert.property(result, 'hdIndex')
})
})
})
@@ -24,27 +24,6 @@ describe('#offer-use-case.js', () => {
})
describe('#ensureFunds', () => {
it('should throw error if wallet does not have enough funds', async () => {
try {
const offerEntity = {
lokadId: 'SWP',
messageType: 1,
messageClass: 1,
tokenId: 'token-id',
buyOrSell: 'sell',
rateInSats: 1000,
minSatsToExchange: 1250,
numTokens: 1
}
await uut.ensureFunds(offerEntity)
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'App wallet does not have enough tokens to satisfy the SELL offer.')
}
})
it('should return true if wallet has enough funds', async () => {
const offerEntity = {
lokadId: 'SWP',
@@ -52,8 +31,8 @@ describe('#offer-use-case.js', () => {
messageClass: 1,
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
buyOrSell: 'sell',
rateInSats: 1000,
minSatsToExchange: 1250,
rateInBaseUnit: 1000,
minUnitsToExchange: 1250,
numTokens: 1
}
+26
View File
@@ -253,6 +253,32 @@ describe('#wallet', () => {
}
})
})
describe('#moveTokens', () => {
it('should move tokens to a new address in the HD wallet', async () => {
// Mock dependencies
sandbox.stub(uut, 'getKeyPair').resolves({
cashAddress: 'bitcoincash:qqsj63493jk4p05zzdgqzc29k5unqtet9vv8l4x0yt',
wif: 'L4qKTMCwjH9jHnYtNh9Vsrxj7Hg6zmoN8E2v7N47UKvNVEjw7FU8',
hdIndex: 6
})
uut.bchWallet = {
sendTokens: async () => 'fake-txid'
}
const inObj = {
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
qty: 1
}
const result = await uut.moveTokens(inObj)
// console.log('result: ', result)
assert.property(result, 'txid')
assert.property(result, 'vout')
assert.property(result, 'hdIndex')
})
})
})
const deleteFile = (filepath) => {
+2 -1
View File
@@ -126,7 +126,8 @@ const wallet = {
getKeyPair: async () => {
return { cashAddress: 'fakeAddr', wif: 'fakeWif', hdIndex: 1 }
},
bchWallet: new MockBchWallet()
bchWallet: new MockBchWallet(),
moveTokens: async () => {}
}
const p2wdb = {
+31 -31
View File
@@ -65,34 +65,34 @@ describe('#order-use-case', () => {
})
})
describe('#moveTokens', () => {
it('should move tokens to the holding address', async () => {
// Mock dependencies
// sandbox
// .stub(uut.adapters.wallet.bchWallet, 'sendTokens')
// .resolves('fakeTxid')
const orderEntity = {
lokadId: 'SWP',
messageType: 1,
messageClass: 1,
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
buyOrSell: 'sell',
rateInSats: 1000,
minSatsToExchange: 0,
numTokens: 1
}
const result = await uut.moveTokens(orderEntity)
// console.log('result: ', result)
assert.property(result, 'txid')
assert.property(result, 'vout')
assert.equal(result.txid, 'fakeTxid')
assert.equal(result.vout, 1)
})
})
// describe('#moveTokens', () => {
// it('should move tokens to the holding address', async () => {
// // Mock dependencies
// // sandbox
// // .stub(uut.adapters.wallet.bchWallet, 'sendTokens')
// // .resolves('fakeTxid')
//
// const orderEntity = {
// lokadId: 'SWP',
// messageType: 1,
// messageClass: 1,
// tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
// buyOrSell: 'sell',
// rateInBaseUnit: 1000,
// minUnitsToExchange: 0,
// numTokens: 1
// }
//
// const result = await uut.moveTokens(orderEntity)
// // console.log('result: ', result)
//
// assert.property(result, 'txid')
// assert.property(result, 'vout')
//
// assert.equal(result.txid, 'fakeTxid')
// assert.equal(result.vout, 1)
// })
// })
describe('#createOrder', () => {
it('should create an order and return the hash', async () => {
@@ -102,8 +102,8 @@ describe('#order-use-case', () => {
messageClass: 1,
tokenId: 'token-id',
buyOrSell: 'sell',
rateInSats: 1000,
minSatsToExchange: 1250,
rateInBaseUnit: 1000,
minUnitsToExchange: 1250,
numTokens: 1
}
@@ -111,7 +111,7 @@ describe('#order-use-case', () => {
// sandbox.stub(uut.adapters.wallet, 'burnPsf').resolves('fakeTxid')
sandbox.stub(uut.orderEntity, 'validate').returns(entryObj)
sandbox.stub(uut, 'ensureFunds').resolves()
sandbox.stub(uut, 'moveTokens').resolves({ txid: 'fakeTxid', vout: 0, hdIndex: 1 })
sandbox.stub(uut.adapters.wallet, 'moveTokens').resolves({ txid: 'fakeTxid', vout: 0, hdIndex: 1 })
sandbox.stub(uut.adapters.wallet.bchWallet, 'getUtxos').resolves()
// sandbox
// .stub(uut.adapters.wallet, 'generateSignature')