fix unit and integration tests

This commit is contained in:
munna0908 2024-12-18 15:01:18 +05:30
parent 8c4d4d3de2
commit 11ccfcac0b
8 changed files with 71 additions and 25 deletions

View File

@ -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,
@ -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,
@ -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,

View File

@ -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
@ -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"),

46
tests/codex/testnat.nim Normal file
View File

@ -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)

View File

@ -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)

View File

@ -144,9 +144,8 @@ template multinodesuite*(name: string, body: untyped) =
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:

View File

@ -26,9 +26,8 @@ ethersuite "Node block expiration tests":
node = 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",

View File

@ -34,8 +34,7 @@ template twonodessuite*(name: string, debug1, debug2: string, body) =
var node1Args = @[
"--api-port=8080",
"--data-dir=" & dataDir1,
"--nat=127.0.0.1",
"--disc-ip=127.0.0.1",
"--nat=none",
"--disc-port=8090",
"--listen-addrs=/ip4/127.0.0.1/tcp/0",
"persistence",
@ -58,8 +57,7 @@ template twonodessuite*(name: string, debug1, debug2: string, body) =
var node2Args = @[
"--api-port=8081",
"--data-dir=" & dataDir2,
"--nat=127.0.0.1",
"--disc-ip=127.0.0.1",
"--nat=none",
"--disc-port=8091",
"--listen-addrs=/ip4/127.0.0.1/tcp/0",
"--bootstrap-node=" & bootstrap,

View File

@ -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"
@ -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",