Emit event when offer is selected

This commit is contained in:
Mark Spanbroek 2022-02-21 14:00:59 +01:00 committed by markspanbroek
parent 05fbd244e2
commit c835ac1cc4
2 changed files with 9 additions and 0 deletions

View File

@ -81,6 +81,8 @@ contract Marketplace is Collateral {
funds.sent += difference;
funds.balance -= difference;
token.transfer(request.client, difference);
emit OfferSelected(id);
}
struct Request {
@ -108,6 +110,7 @@ contract Marketplace is Collateral {
event StorageRequested(bytes32 id, Request request);
event StorageOffered(bytes32 id, Offer offer);
event OfferSelected(bytes32 id);
modifier marketplaceInvariant() {
MarketplaceFunds memory oldFunds = funds;

View File

@ -163,6 +163,12 @@ describe("Marketplace", function () {
switchAccount(client)
})
it("emits event when offer is selected", async function () {
await expect(marketplace.selectOffer(offerId(offer)))
.to.emit(marketplace, "OfferSelected")
.withArgs(offerId(offer))
})
it("returns price difference to client", async function () {
let difference = request.maxPrice - offer.price
let before = await token.balanceOf(client.address)