Skip to content

Commit f800a50

Browse files
authored
[CVAT] Added aurora testnet support (#3488)
1 parent 22809c3 commit f800a50

File tree

13 files changed

+106
-3
lines changed

13 files changed

+106
-3
lines changed

packages/examples/cvat/exchange-oracle/src/.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ POLYGON_AMOY_RPC_API_URL=
3535
POLYGON_AMOY_PRIVATE_KEY=
3636
POLYGON_AMOY_ADDR=
3737

38+
# Aurora Testnet Config
39+
40+
AURORA_TESTNET_RPC_API_URL=
41+
AURORA_TESTNET_PRIVATE_KEY=
42+
AURORA_TESTNET_ADDR=
43+
3844
# Cron Config
3945

4046
PROCESS_JOB_LAUNCHER_WEBHOOKS_INT=

packages/examples/cvat/exchange-oracle/src/chain/web3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ def get_web3(chain_id: Networks):
3232
)
3333
w3.eth.default_account = gas_payer.address
3434
return w3
35+
case Config.aurora_testnet.chain_id:
36+
w3 = Web3(HTTPProvider(Config.aurora_testnet.rpc_api))
37+
gas_payer = w3.eth.account.from_key(Config.aurora_testnet.private_key)
38+
w3.middleware_onion.inject(
39+
SignAndSendRawMiddlewareBuilder.build(Config.aurora_testnet.private_key),
40+
"SignAndSendRawMiddlewareBuilder",
41+
layer=0,
42+
)
43+
w3.eth.default_account = gas_payer.address
44+
return w3
3545
case Config.localhost.chain_id:
3646
w3 = Web3(HTTPProvider(Config.localhost.rpc_api))
3747
gas_payer = w3.eth.account.from_key(Config.localhost.private_key)
@@ -58,6 +68,8 @@ def sign_message(chain_id: Networks, message) -> str:
5868
private_key = Config.polygon_mainnet.private_key
5969
case Config.polygon_amoy.chain_id:
6070
private_key = Config.polygon_amoy.private_key
71+
case Config.aurora_testnet.chain_id:
72+
private_key = Config.aurora_testnet.private_key
6173
case Config.localhost.chain_id:
6274
private_key = Config.localhost.private_key
6375
case _:

packages/examples/cvat/exchange-oracle/src/core/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class PolygonAmoyConfig(_NetworkConfig):
9696
addr = getenv("POLYGON_AMOY_ADDR")
9797

9898

99+
class AuroraTestnetConfig(_NetworkConfig):
100+
chain_id = 1313161555
101+
rpc_api = getenv("AURORA_TESTNET_RPC_API_URL")
102+
private_key = getenv("AURORA_TESTNET_PRIVATE_KEY")
103+
addr = getenv("AURORA_TESTNET_ADDR")
104+
105+
99106
class LocalhostConfig(_NetworkConfig):
100107
chain_id = 1338
101108
rpc_api = getenv("LOCALHOST_RPC_API_URL", "http://blockchain-node:8545")
@@ -329,6 +336,7 @@ class Config:
329336

330337
polygon_mainnet = PolygonMainnetConfig
331338
polygon_amoy = PolygonAmoyConfig
339+
aurora_testnet = AuroraTestnetConfig
332340
localhost = LocalhostConfig
333341

334342
postgres_config = PostgresConfig

packages/examples/cvat/exchange-oracle/src/core/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class Networks(int, Enum, metaclass=BetterEnumMeta):
88
polygon_mainnet = Config.polygon_mainnet.chain_id
99
polygon_amoy = Config.polygon_amoy.chain_id
10+
aurora_testnet = Config.aurora_testnet.chain_id
1011
localhost = Config.localhost.chain_id
1112

1213

packages/examples/cvat/exchange-oracle/src/endpoints/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@greet_router.get("/", description="Endpoint describing the API", response_model=MetaResponse)
1818
def meta_route() -> MetaResponse:
19-
networks = [Config.polygon_mainnet, Config.polygon_amoy]
19+
networks = [Config.polygon_mainnet, Config.polygon_amoy, Config.aurora_testnet]
2020

2121
networks_info = [
2222
{

packages/examples/cvat/exchange-oracle/tests/api/test_webhook_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_incoming_webhook_400_invalid_chain_id(client: TestClient) -> None:
116116
"errors": [
117117
{
118118
"field": "chain_id",
119-
"message": "Input should be 137, 80002 or 1338",
119+
"message": "Input should be 137, 80002, 1313161555 or 1338",
120120
}
121121
]
122122
}

packages/examples/cvat/exchange-oracle/tests/integration/chain/test_web3.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ class PolygonAmoyConfig:
5050
assert w3.eth.default_account == DEFAULT_GAS_PAYER
5151
assert w3.manager._provider.endpoint_uri == PolygonAmoyConfig.rpc_api
5252

53+
def test_get_web3_aurora_testnet(self):
54+
class AuroraTestnetConfig:
55+
chain_id = 1313161555
56+
rpc_api = " https://testnet.aurora.dev"
57+
private_key = DEFAULT_GAS_PAYER_PRIV
58+
59+
with patch("src.chain.web3.Config.aurora_testnet", AuroraTestnetConfig):
60+
w3 = get_web3(ChainId.AURORA_TESTNET.value)
61+
assert isinstance(w3, Web3)
62+
assert w3.eth.default_account == DEFAULT_GAS_PAYER
63+
assert w3.manager._provider.endpoint_uri == AuroraTestnetConfig.rpc_api
64+
5365
def test_get_web3_localhost(self):
5466
w3 = get_web3(ChainId.LOCALHOST.value)
5567
assert isinstance(w3, Web3)
@@ -82,6 +94,19 @@ def test_sign_message_amoy(self):
8294
assert signature == SIGNATURE
8395
assert serialized_message == json.dumps("message")
8496

97+
def test_sign_message_aurora_tesnet(self):
98+
with patch("src.chain.web3.get_web3") as mock_function:
99+
with patch(
100+
"src.chain.web3.Config.aurora_testnet.private_key",
101+
DEFAULT_GAS_PAYER_PRIV,
102+
):
103+
mock_function.return_value = self.w3
104+
signature, serialized_message = sign_message(
105+
ChainId.AURORA_TESTNET.value, "message"
106+
)
107+
assert signature == SIGNATURE
108+
assert serialized_message == json.dumps("message")
109+
85110
def test_sign_message_invalid_chain_id(self):
86111
with pytest.raises(ValueError, match="1234 is not in available list of networks."):
87112
sign_message(1234, "message")

packages/examples/cvat/recording-oracle/src/.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ POLYGON_AMOY_RPC_API_URL=
2626
POLYGON_AMOY_PRIVATE_KEY=
2727
POLYGON_AMOY_ADDR=
2828

29+
# Aurora Testnet Config
30+
31+
AURORA_TESTNET_RPC_API_URL=
32+
AURORA_TESTNET_PRIVATE_KEY=
33+
AURORA_TESTNET_ADDR=
34+
2935
# Cron jobs
3036

3137
PROCESS_EXCHANGE_ORACLE_WEBHOOKS_INT=

packages/examples/cvat/recording-oracle/src/chain/web3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ def get_web3(chain_id: Networks):
3232
)
3333
w3.eth.default_account = gas_payer.address
3434
return w3
35+
case Config.aurora_testnet.chain_id:
36+
w3 = Web3(HTTPProvider(Config.aurora_testnet.rpc_api))
37+
gas_payer = w3.eth.account.from_key(Config.aurora_testnet.private_key)
38+
w3.middleware_onion.inject(
39+
SignAndSendRawMiddlewareBuilder.build(Config.aurora_testnet.private_key),
40+
"SignAndSendRawMiddlewareBuilder",
41+
layer=0,
42+
)
43+
w3.eth.default_account = gas_payer.address
44+
return w3
3545
case Config.localhost.chain_id:
3646
w3 = Web3(HTTPProvider(Config.localhost.rpc_api))
3747
gas_payer = w3.eth.account.from_key(Config.localhost.private_key)
@@ -58,6 +68,8 @@ def sign_message(chain_id: Networks, message) -> tuple:
5868
private_key = Config.polygon_mainnet.private_key
5969
case Config.polygon_amoy.chain_id:
6070
private_key = Config.polygon_amoy.private_key
71+
case Config.aurora_testnet.chain_id:
72+
private_key = Config.aurora_testnet.private_key
6173
case Config.localhost.chain_id:
6274
private_key = Config.localhost.private_key
6375
case _:

packages/examples/cvat/recording-oracle/src/core/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class PolygonAmoyConfig(_NetworkConfig):
7171
addr = getenv("POLYGON_AMOY_ADDR")
7272

7373

74+
class AuroraTestnetConfig(_NetworkConfig):
75+
chain_id = 1313161555
76+
rpc_api = getenv("AURORA_TESTNET_RPC_API_URL")
77+
private_key = getenv("AURORA_TESTNET_PRIVATE_KEY")
78+
addr = getenv("AURORA_TESTNET_ADDR")
79+
80+
7481
class LocalhostConfig(_NetworkConfig):
7582
chain_id = 1338
7683
rpc_api = getenv("LOCALHOST_RPC_API_URL", "http://blockchain-node:8545")
@@ -254,6 +261,7 @@ class Config:
254261

255262
polygon_mainnet = PolygonMainnetConfig
256263
polygon_amoy = PolygonAmoyConfig
264+
aurora_testnet = AuroraTestnetConfig
257265
localhost = LocalhostConfig
258266

259267
postgres_config = Postgres

0 commit comments

Comments
 (0)