From 14ee5d547f3adafb7a8d63eea136154cdb10e1a6 Mon Sep 17 00:00:00 2001 From: Isha Venikar Date: Wed, 18 Sep 2024 15:36:06 +0530 Subject: [PATCH] Check auction creator balance in provider auction --- proto/cerc/auction/v1/auction.proto | 14 +++++----- proto/cerc/auction/v1/tx.proto | 8 +++--- src/auction.test.ts | 41 ++++++++++++++++++----------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/proto/cerc/auction/v1/auction.proto b/proto/cerc/auction/v1/auction.proto index 4720cc9..8f2b74e 100644 --- a/proto/cerc/auction/v1/auction.proto +++ b/proto/cerc/auction/v1/auction.proto @@ -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\"" diff --git a/proto/cerc/auction/v1/tx.proto b/proto/cerc/auction/v1/tx.proto index b454551..a1054d7 100644 --- a/proto/cerc/auction/v1/tx.proto +++ b/proto/cerc/auction/v1/tx.proto @@ -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\"" diff --git a/src/auction.test.ts b/src/auction.test.ts index 4398d77..1e25cec 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -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());