Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
28cf555
location.country should be validated only if it exists
xludx Aug 9, 2019
347e43e
v0.1.113
xludx Aug 9, 2019
0aae07d
getReleaseOutput to return anon ones on mainnet
xludx Aug 29, 2019
0b8b8a6
v0.1.114
xludx Aug 29, 2019
68c7db9
Merge branch 'master' of github.com:particl/omp-lib
xludx Oct 21, 2019
f193674
multiwallet support
xludx Oct 21, 2019
475076f
v0.1.115
xludx Oct 21, 2019
acdacce
v0.1.116
xludx Oct 22, 2019
8bfd95e
getNewStealthAddress(wallet: string, params?: any[])
xludx Oct 22, 2019
0379873
v0.1.117
xludx Oct 22, 2019
8925588
v0.1.118
xludx Oct 22, 2019
4d1b67c
RpcExtKey
xludx Oct 23, 2019
0a0dc78
v0.1.119
xludx Oct 23, 2019
3da11e7
v0.1.120
xludx Oct 23, 2019
8428cf0
extkeyresult
xludx Oct 23, 2019
a91a378
v0.1.121
xludx Oct 23, 2019
60ecef0
RpcExtKeyInfo
xludx Oct 23, 2019
07c0091
v0.1.122
xludx Oct 23, 2019
fc644bf
Allows for listings to provide the escrow release type (blind or anon…
zaSmilingIdiot Nov 4, 2019
c65b903
add Item.SellerInfo
xludx Dec 9, 2019
c38f1b6
0.1.124
xludx Dec 9, 2019
07bd4fe
seller validation
xludx Dec 9, 2019
23b57e8
0.1.125
xludx Dec 9, 2019
8e17cc2
add seller to item hash
xludx Jan 10, 2020
50d93f9
v0.1.126
xludx Jan 10, 2020
4bafaeb
add Item.seller.signature
xludx Jan 14, 2020
7b3ba9a
v0.1.127
xludx Jan 14, 2020
c7bc8ec
v0.1.128
xludx Jan 16, 2020
5ff370a
Changes the MPAction enum values to differentiate between new and old…
zaSmilingIdiot Apr 7, 2020
3dc00d4
Updates enum labels: replace 'NEW' with a more appropriate versioning…
zaSmilingIdiot Apr 7, 2020
c2529b7
mp0.3 seller validation
xludx Apr 9, 2020
d9dd85a
Merge branch 'master' into fix/VariableEscrowReleaseType
xludx Apr 9, 2020
d1eb705
Merge pull request #1 from zaSmilingIdiot/fix/VariableEscrowReleaseType
xludx Apr 9, 2020
fe71241
v0.1.129
xludx Apr 9, 2020
83e32f2
uppercase EscrowReleaseType enum values
xludx Apr 9, 2020
bcd6a57
v0.1.130
xludx Apr 9, 2020
38888a5
Merge pull request #2 from zaSmilingIdiot/update/MPActionEnumChange
xludx Apr 9, 2020
3f3d5ba
v0.1.131
xludx Apr 9, 2020
3a03e97
removed SELLER from HashableItemField
xludx May 7, 2020
d15966a
hasher logging
xludx May 28, 2020
7c7fcb4
FV_MPM fix, compare the string enum values instead of keys
xludx Jun 11, 2020
6aef85a
added isStringAndEnumValue
xludx Jun 11, 2020
648f05a
fixed the obvious problems with the tests after the change to listing…
xludx Jun 11, 2020
44db37d
0.1.135
xludx Jun 11, 2020
d425353
.137, RpcBalances rpc interface, some test changes
xludx Jul 2, 2020
933a279
cleanup and a pretty stupid bid fix
xludx Jul 8, 2020
67f31c6
0.1.138
xludx Jul 8, 2020
bf76d56
EscrowReleaseType and OutputTypes to lowercase, since particld seems …
xludx Jul 22, 2020
e5705c5
0.1.139
xludx Jul 22, 2020
cd4258e
protocoldsn, content validation changes, 0.1.141
xludx Sep 3, 2020
5a70851
hashable validation fix
xludx Sep 4, 2020
d52de78
fixed hashable, added tests, publish 0.1.143
xludx Sep 4, 2020
1a00ce5
0.1.148
xludx Sep 6, 2020
83ed004
remove hasher logs
xludx Sep 7, 2020
609d08b
0.1.150
xludx Sep 7, 2020
27f9ffd
bit of cleanup
xludx Dec 14, 2020
29dea85
Allow for an optional address to be provided to createPrevoutFrom(), …
zaSmilingIdiot Jul 7, 2021
9fab7ea
Merge pull request #1 from zaSmilingIdiot/update/createPrevoutFrom
zaSmilingIdiot Jul 9, 2021
5172828
Merge pull request #3 from zaSmilingIdiot/update/createPrevoutFrom
xludx Jul 9, 2021
1738b8e
bump version
xludx Jul 9, 2021
a8a7d53
bump version
xludx Jul 9, 2021
95cfc15
Re-throw the error when the call to sendTypeTo() errors (in createPre…
zaSmilingIdiot Aug 3, 2021
452547f
Merge pull request #4 from zaSmilingIdiot/fix/bidAccept
xludx Aug 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/bid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * from 'jest';
import { OpenMarketProtocol } from '../src/omp';
import { Cryptocurrency } from '../src/interfaces/crypto';
import { BidConfiguration } from '../src/interfaces/configs';
import { EscrowType } from '../src/interfaces/omp-enums';
import { EscrowType, MPAction } from '../src/interfaces/omp-enums';
import { CoreRpcService } from '../test/rpc.stub';

describe('Bid', () => {
Expand All @@ -11,7 +11,7 @@ describe('Bid', () => {
`{
"version": "0.1.0.0",
"action": {
"type": "MPA_LISTING_ADD",
"type": "${MPAction.MPA_LISTING_ADD}",
"item": {
"information": {
"title": "a 6 month old dog",
Expand Down
172 changes: 123 additions & 49 deletions __tests__/buyflow/madct.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * from 'jest';
import { CtCoreRpcService } from '../../test/rpc-ct.stub';
import { OpenMarketProtocol } from '../../src/omp';
import { Cryptocurrency } from '../../src/interfaces/crypto';
import { Cryptocurrency, OutputType } from '../../src/interfaces/crypto';
import { BidConfiguration } from '../../src/interfaces/configs';
import { EscrowType } from '../../src/interfaces/omp-enums';
import { EscrowType, MPAction } from '../../src/interfaces/omp-enums';
import { toSatoshis, strip, log } from '../../src/util';
import { Rpc } from '../../src/abstract/rpc';
import { RpcUnspentOutput } from '../../src/interfaces/rpc';
import delay from 'delay';

describe('Buyflow: mad ct', () => {

const WALLET = ''; // use the default wallet
const SECOND_WALLET = 'test-wallet'; // second wallet for the purpose of testing multiwallet

let buyer: OpenMarketProtocol;
let seller: OpenMarketProtocol;

Expand All @@ -27,13 +32,30 @@ describe('Buyflow: mad ct', () => {

seller = new OpenMarketProtocol({ network: 'testnet'});
seller.inject(Cryptocurrency.PART, sellerNode1);

if (!(await buyerNode0.walletExists(SECOND_WALLET))) {
await buyerNode0.createWallet(SECOND_WALLET, false, true);
await buyerNode0.setupWallet(SECOND_WALLET);
}
if (!(await sellerNode1.walletExists(SECOND_WALLET))) {
await sellerNode1.createWallet(SECOND_WALLET, false, true);
await sellerNode1.setupWallet(SECOND_WALLET);
}

if (!(await buyerNode0.walletLoaded(SECOND_WALLET))) {
await buyerNode0.loadWallet(SECOND_WALLET);
}
if (!(await sellerNode1.walletLoaded(SECOND_WALLET))) {
await sellerNode1.loadWallet(SECOND_WALLET);
}

});

const ok = JSON.parse(
`{
"version": "0.1.0.0",
"version": "0.3.0",
"action": {
"type": "MPA_LISTING_ADD",
"type": "${MPAction.MPA_LISTING_ADD}",
"item": {
"information": {
"title": "a 6 month old dog",
Expand All @@ -43,6 +65,10 @@ describe('Buyflow: mad ct', () => {
"Animals"
]
},
"seller": {
"address": "pVHUY9AYwNSjbX8f1d4fPgYCkNmZxMC25p",
"signature": "H7yN04IMrwbUgqFXT5Jzr5BPS5vpNrc9deKaY6jkCh0icM5Z3V5rtle/EkugQccw0vk/K6CReQ8sSSDo5W9Vl1I="
},
"payment": {
"type": "SALE",
"escrow": {
Expand Down Expand Up @@ -94,47 +120,56 @@ describe('Buyflow: mad ct', () => {

// Step 1: Buyer does bid
log(' >>>>> Step 1: Buyer does bid');
const bid = await buyer.bid(config, ok);
const bid = await buyer.bid(WALLET, config, ok);
const bid_stripped = strip(bid);
await delay(7000);

const time = Date.now();
await delay(10000);

// Step 2: seller accepts
log(' >>>>> Step 2: seller accepts');
const accept = await seller.accept(ok, bid_stripped);
const accept = await seller.accept(WALLET, ok, bid_stripped);
const accept_stripped = strip(accept);
expect(accept.action['_rawdesttx']).not.toBeCompletedTransaction();
await expectCompletedTransaction(accept.action['_rawdesttx'], false);

// Step 3: buyer signs destroy txn (done), signs bid txn (half)
log(' >>>>> Step 3: buyer signs destroy txn (done), signs bid txn (half)');
await delay(7000);
const lock = await buyer.lock(ok, bid, accept_stripped);
await delay(10000);
const lock = await buyer.lock(WALLET, ok, bid, accept_stripped);
const lock_stripped = strip(lock);

expect(lock.action['_rawdesttx']).not.toBeCompletedTransaction();
await expectCompletedTransaction(lock.action['_rawdesttx'], false);
expect(lock.action['_rawreleasetxunsigned']).toEqual(accept.action['_rawreleasetxunsigned']);

// Step 4: seller signs bid txn (full) and submits
log(' >>>>> Step 4: seller signs bid txn (full) and submits');
const complete = await seller.complete(ok, bid_stripped, accept_stripped, lock_stripped);
expect(complete).toBeCompletedTransaction();
const complete = await seller.complete(WALLET, ok, bid_stripped, accept_stripped, lock_stripped);
await expectCompletedTransaction(complete);

const completeTxid = await buyerNode0.sendRawTransaction(complete);
await sellerNode1.sendRawTransaction(complete);
expect(completeTxid).toBeDefined();

// Step 5: buyer signs release
log(' >>>>> Step 5: buyer signs release');
await delay(10000);
const release = await buyer.release(ok, bid, accept);
expect(release).toBeCompletedTransaction();
await delay(15000);
const release = await buyer.release(WALLET, ok, bid, accept);
await expectCompletedTransaction(release);

const releaseTxid = await buyerNode0.sendRawTransaction(release);
await sellerNode1.sendRawTransaction(release);
expect(releaseTxid).toBeDefined();
log('releaseTxid: ' + releaseTxid);

await delay(10000);
expect(releaseTxid).toBeUtxoWithAmount(buyerNode0, 2);
expect(releaseTxid).toBeUtxoWithAmount(sellerNode1, 3.99995000);
await delay(20000); // 10000 doesnt seem to be enough
await expectUtxoWithAmount(releaseTxid, buyerNode0, 2);
await expectUtxoWithAmount(releaseTxid, sellerNode1, 3.99995000);

log('!!! buyflow release success!');

// await expect(releaseTxid).toBeUtxoWithAmount(buyerNode0, 2);
// await expect(releaseTxid).toBeUtxoWithAmount(sellerNode1, 3.99995000);
// await delay(2000);

}, 600000);

Expand All @@ -143,46 +178,52 @@ describe('Buyflow: mad ct', () => {

// Step1: Buyer does bid
log(' >>>>> Step 1: Buyer does bid');
const bid = await buyer.bid(config, ok);
const bid = await buyer.bid(WALLET, config, ok);
const bid_stripped = strip(bid);
await delay(7000);

// Step 2: seller accepts
log(' >>>>> Step 2: seller accepts');
const accept = await seller.accept(ok, bid_stripped);
const accept = await seller.accept(WALLET, ok, bid_stripped);
const accept_stripped = strip(accept);
expect(accept.action['_rawdesttx']).not.toBeCompletedTransaction();
await expectCompletedTransaction(accept.action['_rawdesttx'], false);
await delay(7000);

// Step 3: buyer signs destroy txn (done), signs bid txn (half)
log(' >>>>> Step 3: buyer signs destroy txn (done), signs bid txn (half)');
const lock = await buyer.lock(ok, bid, accept_stripped);
const lock = await buyer.lock(WALLET, ok, bid, accept_stripped);
const lock_stripped = strip(lock);
expect(lock.action['_rawdesttx']).not.toBeCompletedTransaction();
await expectCompletedTransaction(lock.action['_rawdesttx'], false);
expect(lock.action['_rawreleasetxunsigned']).toEqual(accept.action['_rawreleasetxunsigned']);

// Step 4: seller signs bid txn (full) and submits
log(' >>>>> Step 4: seller signs bid txn (full) and submits');
const complete = await seller.complete(ok, bid_stripped, accept_stripped, lock_stripped);
expect(complete).toBeCompletedTransaction();
const complete = await seller.complete(WALLET, ok, bid_stripped, accept_stripped, lock_stripped);
await expectCompletedTransaction(complete, true);

const completeTxid = await buyerNode0.sendRawTransaction(complete);
await sellerNode1.sendRawTransaction(complete);
expect(completeTxid).toBeDefined();
await delay(10000);
await delay(15000);

// Step 5: seller signs refund
log(' >>>>> Step 5: seller signs refund');
const refund = await seller.refund(ok, bid, accept, lock);
expect(refund).toBeCompletedTransaction();
const refund = await seller.refund(WALLET, ok, bid, accept, lock);
await expectCompletedTransaction(refund, true);

const refundTxid = await buyerNode0.sendRawTransaction(refund);
await sellerNode1.sendRawTransaction(refund);
expect(refundTxid).toBeDefined();

await delay(10000);
expect(refundTxid).toBeUtxoWithAmount(buyerNode0, 4);
expect(refundTxid).toBeUtxoWithAmount(sellerNode1, 1.99995000);
log('refundTxid: ' + refundTxid);
await delay(20000);
// await expect(refundTxid).toBeUtxoWithAmount(buyerNode0, 4);
// await expect(refundTxid).toBeUtxoWithAmount(sellerNode1, 1.99995000);
await expectUtxoWithAmount(refundTxid, buyerNode0, 4);
await expectUtxoWithAmount(refundTxid, sellerNode1, 1.99995000);
// await delay(2000);

log('!!! buyflow refund success!');

}, 600000);

Expand All @@ -191,30 +232,30 @@ describe('Buyflow: mad ct', () => {

// Step 1: Buyer does bid
log(' >>>>> Step 1: Buyer does bid');
const bid = await buyer.bid(config, ok);
const bid = await buyer.bid(WALLET, config, ok);
const bid_stripped = strip(bid);
await delay(10000);

// Step 2: seller accepts
log(' >>>>> Step 2: seller accepts');
const accept = await seller.accept(ok, bid_stripped);
const accept = await seller.accept(WALLET, ok, bid_stripped);
const accept_stripped = strip(accept);

expect(accept.action['_rawdesttx']).not.toBeCompletedTransaction();
await expectCompletedTransaction(accept.action['_rawdesttx'], false);
await delay(10000);

// Step 3: buyer signs destroy txn (done), signs bid txn (half)
log(' >>>>> Step 3: buyer signs destroy txn (done), signs bid txn (half)');
const lock = await buyer.lock(ok, bid_stripped, accept_stripped);
const lock = await buyer.lock(WALLET, ok, bid_stripped, accept_stripped);
const lock_stripped = strip(lock);

expect(lock.action['_rawdesttx']).not.toBeCompletedTransaction();
await expectCompletedTransaction(lock.action['_rawdesttx'], false);
await delay(7000);

// Step 4: seller signs bid txn (full) and submits
log(' >>>>> Step 4: seller signs bid txn (full) and submits');
const complete = await seller.complete(ok, bid_stripped, accept_stripped, lock_stripped);
expect(complete).toBeCompletedTransaction();
const complete = await seller.complete(WALLET, ok, bid_stripped, accept_stripped, lock_stripped);
await expectCompletedTransaction(complete, true);

const completeTxid = await buyerNode0.sendRawTransaction(complete);
expect(completeTxid).toBeDefined();
Expand All @@ -228,7 +269,7 @@ describe('Buyflow: mad ct', () => {
expect(shouldFailToDestroy).toEqual(true);

// Use daemon as a source of truth for what the current time is.
const now = (await buyerNode0.call('getblockchaininfo', []))['mediantime'];
const now = await buyerNode0.getBlockchainInfo().then(value => value.mediantime);
const feasibleFrom = (now + 2880);

// Travelling through time, 3000s in the future!
Expand All @@ -244,20 +285,44 @@ describe('Buyflow: mad ct', () => {
const destroytxid = await buyerNode0.sendRawTransaction(lock.action['_rawdesttx']);
expect(destroytxid).toBeDefined();

log('!!! buyflow destroy success!');

}, 600000);

// tslint:disable:no-duplicated-branches
const expectCompletedTransaction = async (rawtx: any, complete = true) => {
const verify = await buyerNode0.verifyRawTransaction([rawtx]);
const completed = verify['complete'];

if (complete && !completed) {
throw new Error('expected ' + rawtx + ' to be '
+ (complete ? 'completed' : 'incomplete')
+ ', but received ' + completed + ' instead.');
} else if (!complete && completed) {
throw new Error('expected ' + rawtx + ' to be '
+ (complete ? 'completed' : 'incomplete')
+ ', but received ' + completed + ' instead.');
}
};

const expectUtxoWithAmount = async (txid: string, node: Rpc, amount: number) => {
const outputs: RpcUnspentOutput[] = await node.listUnspent(WALLET, OutputType.ANON, 0);

// log(outputs);

const delay = ms => {
return new Promise(resolve => {
return setTimeout(resolve, ms);
const found = outputs.find(utxo => {
log('find: ' + utxo.txid + ' === ' + txid + ', ' + utxo.amount + ' === ' + amount);
return (utxo.txid === txid && utxo.amount === amount);
});
if (!found) {
throw new Error(`expected ${txid} to be found on the node, but didn't find it.`);
}
};

// const expect2: any = Object.assign(expect);

expect.extend({
async toBeCompletedTransaction(rawtx: any): Promise<any> {
const verify = await buyerNode0.call('verifyrawtransaction', [rawtx]);
const verify = await buyerNode0.verifyRawTransaction([rawtx]);
const completed = verify['complete'];
if (completed) {
return {
Expand All @@ -277,7 +342,14 @@ describe('Buyflow: mad ct', () => {

expect.extend({
async toBeUtxoWithAmount(txid: string, node: Rpc, amount: number): Promise<any> {
const found = (await node.call('listunspentanon', [0])).find(utxo => (utxo.txid === txid && utxo.amount === amount));
const outputs: RpcUnspentOutput[] = await node.listUnspent(WALLET, OutputType.ANON, 0);

// log(outputs);

const found = outputs.find(utxo => {
log('find: ' + utxo.txid + ' === ' + txid + ', ' + utxo.amount + ' === ' + amount);
return (utxo.txid === txid && utxo.amount === amount);
});
if (found) {
return {
message: () =>
Expand All @@ -295,22 +367,24 @@ describe('Buyflow: mad ct', () => {
});

const timeTravel = (expectedUnixTime: number, node: Rpc) => {
return node.call('setmocktime', [expectedUnixTime, true]);
return node.call('setmocktime', [expectedUnixTime, true], WALLET);
};

const waitTillJumped = async (expectedUnixTime: number, node: Rpc) => {
return new Promise(async resolve => {
let wait = true;

while (wait) {
const currentTime = (await node.call('getblockchaininfo', []))['mediantime'];

const currentTime = await node.getBlockchainInfo().then(value => value.mediantime);
wait = (currentTime <= expectedUnixTime);
// console.log(wait ? 'waiting..' : ('finished! ' + currentTime + ' > ' + expectedUnixTime ));
log(wait ? 'waiting..' : ('finished! ' + currentTime + ' > ' + expectedUnixTime ));
await delay(1000);
}

resolve();
});

};

});
Loading