I have a following use case:
- The user Jack mint a ERC721 token
- The user Jack approve ERC721 token to be used by marketplace contract
- The user Jake and user Alice independently & asynchronous call approveExchange() function of marketplace contract
- Marketplace contract performs exchange of token.
The issue I faced with during test case is:
Step 4 should be called after step 3 performed by each party. I could add check condition at step 3 and call step 4 in positive case, however the msg.sender in this case would be Jack or Alice, but token might be transferred only by owner or address which has been approved (in real scenario there are multiple token are exchanged at once).
To overcome this I could implement pooling the chain for exchange which are approved by both users, but is there a better way to do this? Is there a way to delegate contract to call its own function by condition?
Thanks!
Code to reproduce
it("On approveSwap() call in positive scenario SwapChain transfers tokens and makes them consumed", async function() {
// TODO complete me
const { contract, contractValue } = await loadFixture(deploy);
await prepareApproveSwapConditions();
const accounts = await ethers.getSigners();
const owner = accounts[0];
const anotherUser = accounts[1];
const notRegisteredUser = accounts[2];
const match = {
_userFirst: owner.address,
_valueOfFirstUser: 0,
_userSecond: anotherUser.address,
_valueOfSecondUser: 1,
_approvedByFirstUser: false,
_approvedBySecondUser: false
}
await contract.connect(owner).approveMatch(match);
await contract.connect(owner).approveMatch(match);
// TODO complete me
// TODO how to delegate contract address to call approveSwap() ?
}
}
Environment
VS Code, hardhat