Skip to content

Commit

Permalink
fix unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
munna0908 authored and marcinczenko committed Dec 19, 2024
1 parent a8487ff commit 16c96bd
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 21 deletions.
15 changes: 9 additions & 6 deletions tests/codex/slots/testbackendfactory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ suite "Test BackendFactory":
let
config = CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
discoveryIp: ValidIpAddress.init(IPv4_any()),
nat: NatConfig(
hasExtIp: false,
nat: NatNone),
metricsAddress: ValidIpAddress.init("127.0.0.1"),
persistenceCmd: PersistenceCmd.prover,
marketplaceAddress: EthAddress.example.some,
Expand All @@ -68,8 +69,9 @@ suite "Test BackendFactory":
let
config = CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
discoveryIp: ValidIpAddress.init(IPv4_any()),
nat: NatConfig(
hasExtIp: false,
nat: NatNone),
metricsAddress: ValidIpAddress.init("127.0.0.1"),
persistenceCmd: PersistenceCmd.prover,
marketplaceAddress: EthAddress.example.some,
Expand All @@ -90,8 +92,9 @@ suite "Test BackendFactory":
let
config = CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
discoveryIp: ValidIpAddress.init(IPv4_any()),
nat: NatConfig(
hasExtIp: false,
nat: NatNone),
metricsAddress: ValidIpAddress.init("127.0.0.1"),
persistenceCmd: PersistenceCmd.prover,
marketplaceAddress: EthAddress.example.some,
Expand Down
7 changes: 4 additions & 3 deletions tests/codex/slots/testprover.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import pkg/codex/conf
import pkg/confutils/defs
import pkg/poseidon2/io
import pkg/codex/utils/poseidon2digest

import pkg/codex/nat
import ./helpers
import ../helpers
import ./backends/helpers
Expand All @@ -43,8 +43,9 @@ suite "Test Prover":
metaDs = metaTmp.newDb()
config = CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
discoveryIp: ValidIpAddress.init(IPv4_any()),
nat: NatConfig(
hasExtIp: false,
nat: NatNone),
metricsAddress: ValidIpAddress.init("127.0.0.1"),
persistenceCmd: PersistenceCmd.prover,
circomR1cs: InputFile("tests/circuits/fixtures/proof_main.r1cs"),
Expand Down
46 changes: 46 additions & 0 deletions tests/codex/testnat.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import std/[unittest, options, net],stew/shims/net as stewNet
import pkg/chronos
import pkg/libp2p/[multiaddress, multihash, multicodec]
import pkg/stew/results

import ../../codex/nat
import ../../codex/utils/natutils
import ../../codex/utils


suite "NAT Address Tests":
test "natedAddress with local addresses":
# Setup test data
let
udpPort = Port(1234)
natConfig = NatConfig(
hasExtIp: true,
extIp:ValidIpAddress.init("8.8.8.8"))

# Create test addresses
localAddr = MultiAddress.init("/ip4/127.0.0.1/tcp/5000").expect("valid multiaddr")
anyAddr = MultiAddress.init("/ip4/0.0.0.0/tcp/5000").expect("valid multiaddr")
publicAddr = MultiAddress.init("/ip4/192.168.1.1/tcp/5000").expect("valid multiaddr")

# Expected results
let
expectedDiscoveryAddrs = @[
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr")
]
expectedlibp2pAddrs = @[
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr")
]

#ipv6Addr = MultiAddress.init("/ip6/::1/tcp/5000").expect("valid multiaddr")
addrs = @[localAddr, anyAddr, publicAddr]

# Test address remapping
let (libp2pAddrs,discoveryAddrs) = natedAddress(natConfig, addrs, udpPort)

# Verify results
check(discoveryAddrs == expectedDiscoveryAddrs)
check(libp2pAddrs == expectedlibp2pAddrs)
10 changes: 6 additions & 4 deletions tests/contracts/testDeployment.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ method getChainId*(provider: MockProvider): Future[UInt256] {.async: (raises:[Pr
proc configFactory(): CodexConf =
CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
discoveryIp: ValidIpAddress.init(IPv4_any()),
nat: NatConfig(
hasExtIp: false,
nat: NatNone),
metricsAddress: ValidIpAddress.init("127.0.0.1"))

proc configFactory(marketplace: Option[EthAddress]): CodexConf =
CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
discoveryIp: ValidIpAddress.init(IPv4_any()),
nat: NatConfig(
hasExtIp: false,
nat: NatNone),
metricsAddress: ValidIpAddress.init("127.0.0.1"),
marketplaceAddress: marketplace)

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/multinodes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ template multinodesuite*(name: string, body: untyped) =
config.addCliOption("--bootstrap-node", bootstrapNode)
config.addCliOption("--api-port", $ await nextFreePort(8080 + nodeIdx))
config.addCliOption("--data-dir", datadir)
config.addCliOption("--nat", "127.0.0.1")
config.addCliOption("--nat", "none")
config.addCliOption("--listen-addrs", "/ip4/127.0.0.1/tcp/0")
config.addCliOption("--disc-ip", "127.0.0.1")
config.addCliOption("--disc-port", $ await nextFreePort(8090 + nodeIdx))

except CodexConfigError as e:
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/testblockexpiration.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ ethersuite "Node block expiration tests":
node = await CodexProcess.startNode(@[
"--api-port=8080",
"--data-dir=" & dataDir,
"--nat=127.0.0.1",
"--nat=none",
"--listen-addrs=/ip4/127.0.0.1/tcp/0",
"--disc-ip=127.0.0.1",
"--disc-port=8090",
"--block-ttl=" & $blockTtlSeconds,
"--block-mi=1",
Expand Down
6 changes: 2 additions & 4 deletions tests/testTaiko.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ suite "Taiko L2 Integration Tests":
node1 = startNode([
"--data-dir=" & createTempDir("", ""),
"--api-port=8080",
"--nat=127.0.0.1",
"--disc-ip=127.0.0.1",
"--nat=none",
"--disc-port=8090",
"--persistence",
"--eth-provider=https://rpc.test.taiko.xyz"
Expand All @@ -34,8 +33,7 @@ suite "Taiko L2 Integration Tests":
node2 = startNode([
"--data-dir=" & createTempDir("", ""),
"--api-port=8081",
"--nat=127.0.0.1",
"--disc-ip=127.0.0.1",
"--nat=none",
"--disc-port=8091",
"--bootstrap-node=" & bootstrap,
"--persistence",
Expand Down

0 comments on commit 16c96bd

Please sign in to comment.