I have a function that have a modifier that it must be the owner before it can cancel the order and I'm using the nested mapping that i've created for this struct as below
//mapping
mapping(bytes32 => mapping(uint256 => Order)) private s_orders;
mapping(bytes32 => mapping(uint256 => bool)) public s_orderCancelled;
//struct
struct Order {
uint256 id;
address trader;
Status status;
bytes32 ticker;
uint256 amount;
uint256 filled;
uint256 price;
uint256 date;
}
//function
function cancelOrder(bytes32 _ticker, uint256 _id) external {
Order storage orders = s_orders[_ticker][_id];
if (address(orders.trader) != msg.sender) revert Exchange__NotOwner();
if (orders.id == _id) revert Exchange__InvalidId();
s_orderCancelled[_ticker][_id] = true;
}
And I'm getting an error reverted with custom error 'Exchange__NotOwner() with my test script below:
beforeEach(async () => {
await dex.connect(trader1).depositToken(DAI, amount);
transaction = await dex
.connect(trader1)
.createLimitOrder(REP, tradeAmount, price1, Status.BUY);
result = await transaction.wait();
transaction = await dex.connect(trader1).cancelOrder(REP, 1);
result = await transaction.wait();
await dex.connect(trader2).depositToken(REP, amount);
transaction = await dex
.connect(trader2)
.createMarketOrder(REP, tradeAmount, Status.SELL);
result = await transaction.wait();
transaction = await dex.connect(trader2).cancelOrder(REP, 2);
result = await transaction.wait();
});
it("updates cancelled orders", async () => {
expect(await dex.s_orderCancelled(REP, 1)).to.equal(true);
expect(await dex.s_orderCancelled(REP, 2)).to.equal(true);
});
});
not sure which syntax is wrong here