Check auction creator balance in provider auction

This commit is contained in:
Isha Venikar 2024-09-18 15:36:06 +05:30
parent 216199fe47
commit 14ee5d547f
3 changed files with 35 additions and 28 deletions

View File

@ -40,7 +40,7 @@ message Params {
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
];
// Minimum acceptable bid amount
// Minimum acceptable bid amount (for vickrey auctions)
cosmos.base.v1beta1.Coin minimum_bid = 5 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
@ -54,9 +54,7 @@ message Auction {
string id = 1;
// Auction's kind (vickrey | provider)
string kind = 2 [
(gogoproto.moretags) = "json:\"kind\" yaml:\"kind\""
];
string kind = 2 [ (gogoproto.moretags) = "json:\"kind\" yaml:\"kind\"" ];
string status = 3;
@ -95,13 +93,13 @@ message Auction {
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
];
// Minimum acceptable bid amount for a valid commit
// Minimum acceptable bid amount for a valid commit (for vickrey auctions)
cosmos.base.v1beta1.Coin minimum_bid = 10 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
];
// Addresses of the winners (one for vickrey auctions and can be multiple for provider auctions)
// Winner's address for Vickrey auctions, can be multiple for provider auctions
repeated string winner_addresses = 11;
// Winning bids, i.e., the best bids
@ -110,13 +108,13 @@ message Auction {
(gogoproto.moretags) = "json:\"winning_bids\" yaml:\"winning_bids\""
];
// Amount the winner pays, i.e. the second best bid
// Amount the winner pays (vickrey auction) or is paid (provider auction)
cosmos.base.v1beta1.Coin winning_price = 13 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"winning_price\" yaml:\"winning_price\""
];
// Maximum acceptable bid amount for a valid commit for service provider auctions
// Maximum acceptable bid amount (for provider auctions)
cosmos.base.v1beta1.Coin max_price = 14 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"max_price\" yaml:\"max_price\""

View File

@ -67,7 +67,7 @@ message MsgCreateAuction {
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
];
// Minimum acceptable bid amount
// Minimum acceptable bid amount (for vickrey auctions)
cosmos.base.v1beta1.Coin minimum_bid = 5 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
@ -78,11 +78,9 @@ message MsgCreateAuction {
[ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ];
// Auction's kind (vickrey | provider)
string kind = 7 [
(gogoproto.moretags) = "json:\"kind\" yaml:\"kind\""
];
string kind = 7 [ (gogoproto.moretags) = "json:\"kind\" yaml:\"kind\"" ];
// Maximum acceptable bid amount (for service provider auctions)
// Maximum acceptable bid amount (for provider auctions)
cosmos.base.v1beta1.Coin max_price = 8 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"max_price\" yaml:\"max_price\""

View File

@ -122,7 +122,7 @@ const createAuctionTests = () => {
setTimeout(done, waitTime);
});
test('Check auction winner, status, and balance.', async () => {
test('Check auction winner, status, and winner balance.', async () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('completed');
@ -133,10 +133,9 @@ const createAuctionTests = () => {
expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`);
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
const initialBalance = 20000000;
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = (initialBalance - winningBidAmount).toString();
const bidderInitialBalance = 20000000;
const winningPriceAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = (bidderInitialBalance - winningPriceAmount).toString();
const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]);
expect(winnerAccountObj).toBeDefined();
@ -149,7 +148,7 @@ const createAuctionTests = () => {
});
};
const createSPAuctionTests = () => {
const createProviderAuctionTests = () => {
let registry: Registry;
let auctionId: string;
@ -159,7 +158,7 @@ const createSPAuctionTests = () => {
let bidAmounts: { type: string, quantity: string }[] = [];
beforeAll(async () => {
console.log('Running service provider auction tests');
console.log('Running provider auction tests');
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
@ -181,7 +180,7 @@ const createSPAuctionTests = () => {
}
});
test('Create service provider auction', async () => {
test('Create provider auction', async () => {
const maxPrice = {
denom: 'alnt',
amount: '100000000'
@ -245,7 +244,7 @@ const createSPAuctionTests = () => {
setTimeout(done, waitTime);
});
test('Check auction winner, status, and balance.', async () => {
test('Check auction winner, status, and bidder balance.', async () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('completed');
@ -258,23 +257,35 @@ const createSPAuctionTests = () => {
expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`);
const initialBalance = 20000000;
const bidderInitialBalance = 20000000;
const [winnerAccountObj] = await registry.getAccounts([winner.address]);
expect(winnerAccountObj).toBeDefined();
expect(winnerAccountObj.address).toBe(winner.address);
const [{ type, quantity: currentBalance }] = winnerAccountObj.balance;
expect(type).toBe(DENOM);
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = bidderInitialBalance + winningBidAmount;
const expectedBalance = (parseInt(currentBalance, 10) + winningBidAmount).toString();
expect(expectedBalance).toEqual(initialBalance.toString());
expect(type).toBe(DENOM);
expect(currentBalance).toEqual(expectedBalance);
}
const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
expect(creatorAccountObj).toBeDefined();
expect(creatorAccountObj.address).toBe(auctionCreatorAccount.address);
const [{ type, quantity: currentBalance }] = creatorAccountObj.balance;
const creatorInitialBalance = 1000000000000;
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
const expectedBalance = creatorInitialBalance - (winningBidAmount * 3);
expect(type).toBe(DENOM);
expect(currentBalance).toEqual(expectedBalance);
});
};
describe('Vickrey Auction', () => createAuctionTests());
describe('Service provider Auction', () => createSPAuctionTests());
describe('Provider Auction', () => createProviderAuctionTests());