Add a test for release-funds command and use multiple accounts
This commit is contained in:
parent
cbf319e97e
commit
15bf0a3cf2
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,7 @@ dist/*
|
|||||||
out
|
out
|
||||||
|
|
||||||
config.yml
|
config.yml
|
||||||
|
.env
|
||||||
*~
|
*~
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
170
test/cli.test.ts
170
test/cli.test.ts
@ -715,13 +715,43 @@ describe('Test laconic CLI commands', () => {
|
|||||||
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Provider Auction operations', () => {
|
describe.only('Provider Auction operations', () => {
|
||||||
const commitFee = 1000;
|
const commitFee = 1000;
|
||||||
const revealFee = 1000;
|
const revealFee = 1000;
|
||||||
const maxPrice = 1000000;
|
const maxPrice = 1000000;
|
||||||
const numProviders = 5;
|
const numProviders = 2;
|
||||||
const bidAmount = 25000;
|
const bidderInitialBlanace = 1000000000;
|
||||||
let bidRevealFilePath: string;
|
const txFees = 200000;
|
||||||
|
testAuctionId = '5e9dd5501e965f25db4fa62635d0ce5f6c59d73ab1a2ea999f8c5bf2f6fb6350';
|
||||||
|
|
||||||
|
const bidderAccounts = [
|
||||||
|
{
|
||||||
|
privateKey: 'f40f8e2c9ba70595b6d1cf3bcc47ba539e7d6ad2bcdb16e26c1e369378fd5a55',
|
||||||
|
address: 'laconic13cd6ntlcf5y0zmafg6wf96y6vsnq46xagpmjtc',
|
||||||
|
bidAmount: 25000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
privateKey: '2c70e81c285e12f196837911aa258b11dff7e4189fc0f11e28cb228956807881',
|
||||||
|
address: 'laconic15x7sw49w3x2pahjlr48hunp5gpr7hm54eg3f8h',
|
||||||
|
bidAmount: 25300
|
||||||
|
},
|
||||||
|
{
|
||||||
|
privateKey: '1d3a47900e1a5980b171419ac700e779330bc0f85389a4113ff608ca314e25bb',
|
||||||
|
address: 'laconic1lkgay8ejvcwmngj3jua2ancdxxkukecz7hty89',
|
||||||
|
bidAmount: 25200
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const winnerAccounts = [bidderAccounts[0], bidderAccounts[2]];
|
||||||
|
const winnerPrice = bidderAccounts[2].bidAmount;
|
||||||
|
|
||||||
|
const bidRevealFilePaths: string[] = [];
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
// Fund all bidder accounts
|
||||||
|
bidderAccounts.forEach(account => {
|
||||||
|
spawnSync('laconic', ['registry', 'tokens', 'send', '--address', account.address, '--type', TOKEN_TYPE, '--quantity', bidderInitialBlanace.toString()]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --max-price <max_price> --num-providers <num_providers>', async () => {
|
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --max-price <max_price> --num-providers <num_providers>', async () => {
|
||||||
const createAuctionResult = spawnSync('laconic', [
|
const createAuctionResult = spawnSync('laconic', [
|
||||||
@ -763,65 +793,71 @@ describe('Test laconic CLI commands', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
for (const bidderAccount of bidderAccounts) {
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidderAccount.bidAmount.toString(), TOKEN_TYPE, '--txKey', bidderAccount.privateKey]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
// Expected output
|
// Expected output
|
||||||
expect(outputObj.reveal_file).toBeDefined();
|
expect(outputObj.reveal_file).toBeDefined();
|
||||||
|
|
||||||
bidRevealFilePath = outputObj.reveal_file;
|
bidRevealFilePaths.push(outputObj.reveal_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedBids = bidderAccounts.map(account => ({
|
||||||
|
bidderAddress: account.address,
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
bidAmount: { quantity: 0 }
|
||||||
|
}));
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
winnerAddresses: [],
|
||||||
|
winnerBids: [],
|
||||||
|
bids: expectedBids
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
||||||
// Wait for auction commits duration (60s)
|
// Wait for auction commits duration (60s)
|
||||||
await delay(AUCTION_COMMIT_DURATION * 1000);
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
||||||
|
|
||||||
let auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
||||||
let auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
ownerAddress: testAccount,
|
|
||||||
winnerAddresses: [],
|
|
||||||
winnerBids: [],
|
|
||||||
bids: [{
|
|
||||||
bidderAddress: testAccount,
|
|
||||||
status: AUCTION_STATUS.COMMIT,
|
|
||||||
bidAmount: { quantity: 0 }
|
|
||||||
}]
|
|
||||||
};
|
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
||||||
|
|
||||||
// Reveal bid
|
// Reveal bid
|
||||||
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
|
for (let i = 0; i < bidderAccounts.length; i++) {
|
||||||
const outputObj = checkResultAndRetrieveOutput(result);
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePaths[i], '--txKey', bidderAccounts[i].privateKey]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
// Expected output
|
// Expected output
|
||||||
expect(outputObj).toEqual({ success: true });
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePath, 'utf8'));
|
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePaths[i], 'utf8'));
|
||||||
expect(revealObject).toMatchObject({
|
expect(revealObject).toMatchObject({
|
||||||
chainId: CHAIN_ID,
|
chainId: CHAIN_ID,
|
||||||
auctionId: testAuctionId,
|
auctionId: testAuctionId,
|
||||||
bidderAddress: testAccount,
|
bidderAddress: bidderAccounts[i].address,
|
||||||
bidAmount: `${bidAmount}${TOKEN_TYPE}`
|
bidAmount: `${bidderAccounts[i].bidAmount}${TOKEN_TYPE}`
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Get auction with revealed bid
|
// Get auction with revealed bid
|
||||||
auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedBids = bidderAccounts.map(account => ({
|
||||||
|
bidderAddress: account.address,
|
||||||
|
status: AUCTION_STATUS.REVEAL,
|
||||||
|
bidAmount: { quantity: account.bidAmount }
|
||||||
|
}));
|
||||||
const expectedAuctionObjPartialOnBidReveal = {
|
const expectedAuctionObjPartialOnBidReveal = {
|
||||||
status: AUCTION_STATUS.REVEAL,
|
status: AUCTION_STATUS.REVEAL,
|
||||||
winnerAddresses: [],
|
winnerAddresses: [],
|
||||||
bids: [{
|
bids: expectedBids
|
||||||
bidderAddress: testAccount,
|
|
||||||
status: AUCTION_STATUS.REVEAL,
|
|
||||||
bidAmount: { quantity: bidAmount }
|
|
||||||
}]
|
|
||||||
};
|
};
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
||||||
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
}, (AUCTION_COMMIT_DURATION + 60) * 1000);
|
||||||
|
|
||||||
test('laconic registry auction get <auction_id>', async () => {
|
test('laconic registry auction get <auction_id>', async () => {
|
||||||
// Wait for auction reveals duration (60s)
|
// Wait for auction reveals duration (60s)
|
||||||
@ -830,15 +866,53 @@ describe('Test laconic CLI commands', () => {
|
|||||||
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedWinnerAddresses = winnerAccounts.map(account => account.address);
|
||||||
|
const expectedWinnerBids = winnerAccounts.map(account => ({ quantity: account.bidAmount }));
|
||||||
|
|
||||||
const expectedAuctionObjPartial = {
|
const expectedAuctionObjPartial = {
|
||||||
status: AUCTION_STATUS.COMPLETED,
|
status: AUCTION_STATUS.COMPLETED,
|
||||||
ownerAddress: testAccount,
|
ownerAddress: testAccount,
|
||||||
winnerAddresses: [testAccount],
|
winnerAddresses: expectedWinnerAddresses,
|
||||||
winnerBids: [{ quantity: bidAmount }],
|
winnerBids: expectedWinnerBids,
|
||||||
winnerPrice: { quantity: bidAmount }
|
winnerPrice: { quantity: winnerPrice },
|
||||||
|
fundsReleased: false
|
||||||
};
|
};
|
||||||
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
}, (AUCTION_REVEAL_DURATION + 5) * 1000);
|
||||||
|
|
||||||
|
test('laconic registry auction release-funds <auction_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'release-funds', testAuctionId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.COMPLETED,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
fundsReleased: true
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
|
||||||
|
const expectedBalances = [
|
||||||
|
bidderInitialBlanace - (commitFee) - (2 * txFees) + winnerPrice,
|
||||||
|
bidderInitialBlanace - (commitFee) - (2 * txFees),
|
||||||
|
bidderInitialBlanace - (commitFee) - (2 * txFees) + winnerPrice
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 0; i < bidderAccounts.length; i++) {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'account', 'get', '--address', bidderAccounts[i].address]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected account
|
||||||
|
const expectedAccount = getAccountObj({ address: bidderAccounts[i].address, balance: expectedBalances[i] });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Gas and fees config', () => {
|
describe('Gas and fees config', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user