mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-03 00:24:43 +00:00
2e5c28781c
Integrate dagger contracts from `nim-dagger-contracts` repo. Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`. Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`. We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this? Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
43 lines
1.1 KiB
Nim
43 lines
1.1 KiB
Nim
import pkg/asynctest
|
|
import pkg/chronos
|
|
import pkg/nimcrypto
|
|
import pkg/contractabi
|
|
import dagger/contracts
|
|
import ./ethertest
|
|
import ./examples
|
|
|
|
suite "Marketplace":
|
|
|
|
test "hashes requests for storage":
|
|
let request = StorageRequest.example
|
|
let encoding = AbiEncoder.encode: (
|
|
"[dagger.request.v1]",
|
|
request.duration,
|
|
request.size,
|
|
request.contentHash,
|
|
request.proofPeriod,
|
|
request.proofTimeout,
|
|
request.nonce
|
|
)
|
|
let expectedHash = keccak256.digest(encoding).data
|
|
check hashRequest(request) == expectedHash
|
|
|
|
test "hashes bids":
|
|
let bid = StorageBid.example
|
|
let encoding = AbiEncoder.encode: (
|
|
"[dagger.bid.v1]",
|
|
bid.requestHash,
|
|
bid.bidExpiry,
|
|
bid.price
|
|
)
|
|
let expectedHash = keccak256.digest(encoding).data
|
|
check hashBid(bid) == expectedHash
|
|
|
|
ethersuite "Marketplace signatures":
|
|
|
|
test "signs request and bid hashes":
|
|
let hash = hashRequest(StorageRequest.example)
|
|
let signer = provider.getSigner()
|
|
let signature = await signer.signMessage(@hash)
|
|
check signature.len == 65
|