nim-codex/tests/contracts/testDeployment.nim
Dmitriy Ryajov bd594c9aaf
Create memory-leak detecting test suite (#226)
* adding tracker for streamstore

* adding tracker tests

* Sets up tracker helper functions and closes streams in testnode.nim

* Deploying checksuite for memory leak tracker checking.

* Successfully deploys checksuite and asyncchecksuite.

* Fix leak in testpor.nim

* Fixes leaked storestream in testnetwork.nim

* Fixes integration tests

* Cleanup

* cleanup comment by Mark

---------

Co-authored-by: benbierens <thatbenbierens@gmail.com>
2023-06-22 12:01:21 -06:00

47 lines
1.6 KiB
Nim

import pkg/asynctest
import pkg/ethers
import codex/contracts/deployment
import codex/conf
import codex/contracts
import ../checktest
type MockProvider = ref object of Provider
chainId*: UInt256
method getChainId*(provider: MockProvider): Future[UInt256] {.async.} =
return provider.chainId
proc configFactory(): CodexConf =
CodexConf(cmd: noCommand, nat: ValidIpAddress.init("127.0.0.1"), discoveryIp: ValidIpAddress.init(IPv4_any()), metricsAddress: ValidIpAddress.init("127.0.0.1"))
proc configFactory(marketplace: Option[EthAddress]): CodexConf =
CodexConf(cmd: noCommand, nat: ValidIpAddress.init("127.0.0.1"), discoveryIp: ValidIpAddress.init(IPv4_any()), metricsAddress: ValidIpAddress.init("127.0.0.1"), marketplaceAddress: marketplace)
asyncchecksuite "Deployment":
let provider = MockProvider()
test "uses conf value as priority":
let deployment = Deployment.new(provider, configFactory(EthAddress.init("0x59b670e9fA9D0A427751Af201D676719a970aaaa")))
provider.chainId = 1.u256
let address = await deployment.address(Marketplace)
check address.isSome
check $(!address) == "0x59b670e9fa9d0a427751af201d676719a970aaaa"
test "uses chainId hardcoded values as fallback":
let deployment = Deployment.new(provider, configFactory())
provider.chainId = 31337.u256
let address = await deployment.address(Marketplace)
check address.isSome
check $(!address) == "0x59b670e9fa9d0a427751af201d676719a970857b"
test "return none for unknown networks":
let deployment = Deployment.new(provider, configFactory())
provider.chainId = 1.u256
let address = await deployment.address(Marketplace)
check address.isNone