Skip to content

chore(marketplace): use hardhat ignition #1195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion codex/contracts/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
rewardRecipient: ?Address
configuration: ?MarketplaceConfig
requestCache: LruCache[string, StorageRequest]
allowanceLock: AsyncLock

MarketSubscription = market.Subscription
EventSubscription = ethers.Subscription
Expand Down Expand Up @@ -76,14 +77,30 @@

return resolvedConfig

template withAllowanceLock*(market: OnChainMarket, body: untyped) =
if market.allowanceLock.isNil:
market.allowanceLock = newAsyncLock()
await market.allowanceLock.acquire()

Check warning on line 83 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L81-L83

Added lines #L81 - L83 were not covered by tests
try:
body
finally:
try:
market.allowanceLock.release()
except AsyncLockError as error:
raise newException(Defect, error.msg, error)

Check warning on line 91 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L85-L91

Added lines #L85 - L91 were not covered by tests
proc approveFunds(
market: OnChainMarket, amount: UInt256
) {.async: (raises: [CancelledError, MarketError]).} =
debug "Approving tokens", amount
convertEthersError("Failed to approve funds"):
let tokenAddress = await market.contract.token()
let token = Erc20Token.new(tokenAddress, market.signer)
discard await token.increaseAllowance(market.contract.address(), amount).confirm(1)
let owner = await market.signer.getAddress()
let spender = market.contract.address
market.withAllowanceLock:
let allowance = await token.allowance(owner, spender)
discard await token.approve(spender, allowance + amount).confirm(1)

Check warning on line 103 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L99-L103

Added lines #L99 - L103 were not covered by tests

method loadConfig*(
market: OnChainMarket
Expand Down
2 changes: 2 additions & 0 deletions tests/contracts/testMarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ ethersuite "On-Chain Market":

let (_, fromTime) = await ethProvider.blockNumberAndTimestamp(BlockTag.latest)

await ethProvider.advanceTime(1.u256)

await market.reserveSlot(request.id, 1.uint64)
await market.reserveSlot(request.id, 2.uint64)
await market.fillSlot(request.id, 1.uint64, proof, request.ask.collateralPerSlot)
Expand Down
23 changes: 22 additions & 1 deletion tests/integration/hardhatprocess.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,28 @@ method start*(node: HardhatProcess) {.async.} =
node.process = await startProcess(
node.executable,
node.workingDir,
@["node", "--export", "deployment-localhost.json"].concat(node.arguments),
@["node"].concat(node.arguments),
options = poptions,
stdoutHandle = AsyncProcess.Pipe,
)

discard await startProcess(
node.executable,
node.workingDir,
@["node", "run", "scripts/mine.js", "--network", "localhost"].concat(
node.arguments
),
options = poptions,
stdoutHandle = AsyncProcess.Pipe,
)

discard await startProcess(
node.executable,
node.workingDir,
@[
"node", "ignition", "deploy", "ignition/modules/marketplace.js", "--network",
"localhost",
].concat(node.arguments),
options = poptions,
stdoutHandle = AsyncProcess.Pipe,
)
Expand Down
2 changes: 1 addition & 1 deletion vendor/codex-contracts-eth
Loading