Skip to content

Commit

Permalink
Merge pull request #89 from valory-xyz/scripts
Browse files Browse the repository at this point in the history
Fix requests count and scripts
  • Loading branch information
mariapiamo authored Jan 24, 2025
2 parents 47b6601 + 3752f7a commit 71ccca9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
15 changes: 10 additions & 5 deletions contracts/MechMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct RequestInfo {
/// @author Andrey Lebedev - <[email protected]>
/// @author Silvere Gangloff - <[email protected]>
contract MechMarketplace is IErrorsMarketplace {

Check warning on line 53 in contracts/MechMarketplace.sol

View workflow job for this annotation

GitHub Actions / build

Contract has 18 states declarations but allowed no more than 15
event CreateMech(address indexed mech, uint256 indexed serviceId);
event CreateMech(address indexed mech, uint256 indexed serviceId, address indexed mechFactory);
event OwnerUpdated(address indexed owner);
event ImplementationUpdated(address indexed implementation);
event MarketplaceParamsUpdated(uint256 fee, uint256 minResponseTimeout, uint256 maxResponseTimeout);
Expand Down Expand Up @@ -440,6 +440,7 @@ contract MechMarketplace is IErrorsMarketplace {
revert UnauthorizedAccount(mechFactory);
}

// Create mech
mech = IMechFactory(mechFactory).createMech(serviceRegistry, serviceId, payload);

// This should never be the case
Expand All @@ -453,7 +454,7 @@ contract MechMarketplace is IErrorsMarketplace {
mapServiceIdMech[serviceId] = mech;
numMechs++;

emit CreateMech(mech, serviceId);
emit CreateMech(mech, serviceId, mechFactory);
}

/// @dev Sets mech factory statues.
Expand Down Expand Up @@ -755,12 +756,16 @@ contract MechMarketplace is IErrorsMarketplace {
// Adjust requester nonce values
mapNonces[requester] = nonce;

// Record the request count
mapRequestCounts[requester] += numRequests;
// Increase the amount of requester delivered requests
mapDeliveryCounts[requester]++;
mapDeliveryCounts[requester] += numRequests;
// Increase the amount of mech delivery counts
mapMechDeliveryCounts[msg.sender]++;
mapMechDeliveryCounts[msg.sender] += numRequests;
// Increase the amount of mech service multisig delivered requests
mapMechServiceDeliveryCounts[mechServiceMultisig]++;
mapMechServiceDeliveryCounts[mechServiceMultisig] += numRequests;
// Increase the total number of requests
numTotalRequests += numRequests;

// Increase mech requester karma
IKarma(karma).changeRequesterMechKarma(requester, msg.sender, int256(numRequests));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ const main = async () => {
const deployer = signers[0];
console.log("Deployer:", deployer.address);

// Get requester balance
const subscription = await ethers.getContractAt("MockNvmSubscriptionNative", parsedData.subscriptionNFTAddress);
const subscriptionBalance = await subscription.balanceOf(deployer.address, parsedData.subscriptionTokenId);
console.log("subscriptionBalance", subscriptionBalance);

// Transfer to accounts
// Get requester balances
const accounts = ["", ""];
const amounts = [100, 100];

const subscription = await ethers.getContractAt("MockNvmSubscriptionNative", parsedData.subscriptionNFTAddress);
for (let i = 0; i < accounts.length; i++) {
await subscription.safeTransferFrom(deployer.address, accounts[i], parsedData.subscriptionTokenId, amounts[i], "0x");
const subscriptionBalance = await subscription.balanceOf(accounts[i], parsedData.subscriptionTokenId);
console.log("account:", accounts[i]);
console.log("subscriptionBalance:", subscriptionBalance);
//await subscription.safeTransferFrom(deployer.address, accounts[i], parsedData.subscriptionTokenId, amounts[i], "0x");
}
};

Expand Down
35 changes: 35 additions & 0 deletions test/MechFixedPriceNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ describe("MechFixedPriceNative", function () {
// Deliver a request
await priorityMech.deliverToMarketplace([requestIds[0]], [data]);

let numRequestCounts = await mechMarketplace.mapRequestCounts(deployer.address);
expect(numRequestCounts).to.equal(1);
numRequestCounts = await mechMarketplace.mapDeliveryCounts(deployer.address);
expect(numRequestCounts).to.equal(1);
numRequestCounts = await mechMarketplace.mapMechDeliveryCounts(priorityMech.address);
expect(numRequestCounts).to.equal(1);
numRequestCounts = await mechMarketplace.mapMechServiceDeliveryCounts(deployer.address);
expect(numRequestCounts).to.equal(1);
numRequestCounts = await mechMarketplace.numTotalRequests();
expect(numRequestCounts).to.equal(1);

// Check request Ids
uRequestIds = await priorityMech.getUndeliveredRequestIds(0, 0);
expect(uRequestIds.length).to.equal(0);
Expand Down Expand Up @@ -526,6 +537,18 @@ describe("MechFixedPriceNative", function () {
// Deliver all requests
await priorityMech.deliverToMarketplace(requestIds, datas);

// Check requests counts: first request plus a batch of numRequests requests
numRequestCounts = await mechMarketplace.mapRequestCounts(deployer.address);
expect(numRequestCounts).to.equal(numRequests + 1);
numRequestCounts = await mechMarketplace.mapDeliveryCounts(deployer.address);
expect(numRequestCounts).to.equal(numRequests + 1);
numRequestCounts = await mechMarketplace.mapMechDeliveryCounts(priorityMech.address);
expect(numRequestCounts).to.equal(numRequests + 1);
numRequestCounts = await mechMarketplace.mapMechServiceDeliveryCounts(deployer.address);
expect(numRequestCounts).to.equal(numRequests + 1);
numRequestCounts = await mechMarketplace.numTotalRequests();
expect(numRequestCounts).to.equal(numRequests + 1);

// Check request Ids
uRequestIds = await priorityMech.getUndeliveredRequestIds(0, 0);
expect(uRequestIds.length).to.equal(0);
Expand Down Expand Up @@ -713,6 +736,18 @@ describe("MechFixedPriceNative", function () {
// Deliver requests
await priorityMech.deliverMarketplaceWithSignatures(deployer.address, datas, signatures, datas,
deliveryRates, "0x");

// Check requests counts
let numRequestCounts = await mechMarketplace.mapRequestCounts(deployer.address);
expect(numRequestCounts).to.equal(numRequests);
numRequestCounts = await mechMarketplace.mapDeliveryCounts(deployer.address);
expect(numRequestCounts).to.equal(numRequests);
numRequestCounts = await mechMarketplace.mapMechDeliveryCounts(priorityMech.address);
expect(numRequestCounts).to.equal(numRequests);
numRequestCounts = await mechMarketplace.mapMechServiceDeliveryCounts(deployer.address);
expect(numRequestCounts).to.equal(numRequests);
numRequestCounts = await mechMarketplace.numTotalRequests();
expect(numRequestCounts).to.equal(numRequests);
});

it("Requests with signatures for contracts", async function () {
Expand Down

0 comments on commit 71ccca9

Please sign in to comment.