Skip to content

Commit 6f39a83

Browse files
authored
Add unit tests for custom dYdX types (#2163)
1 parent 90563d7 commit 6f39a83

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -------------------------------------------------------------------------------------------------
2+
# Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3+
# https://nautechsystems.io
4+
#
5+
# Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6+
# You may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# -------------------------------------------------------------------------------------------------
15+
"""
16+
Unit tests for the dYdX types.
17+
"""
18+
19+
from decimal import Decimal
20+
21+
from nautilus_trader.adapters.dydx.common.types import DYDXInternalError
22+
from nautilus_trader.adapters.dydx.common.types import DYDXOraclePrice
23+
from nautilus_trader.model.identifiers import InstrumentId
24+
25+
26+
def test_dydx_internal_error() -> None:
27+
"""
28+
Test the DYDXInternalError type.
29+
"""
30+
# Arrange
31+
data = DYDXInternalError(error_msg="internal error", ts_init=5, ts_event=6)
32+
33+
# Act
34+
data_dict = data.to_dict()
35+
data_from_dict = DYDXInternalError.from_dict(data_dict)
36+
37+
# Assert
38+
assert data.error_msg == data_from_dict.error_msg
39+
assert data.ts_event == data_from_dict.ts_event
40+
assert data.ts_init == data_from_dict.ts_init
41+
42+
43+
def test_dydx_oracle_price(instrument_id: InstrumentId) -> None:
44+
"""
45+
Test the DYDXOraclePrice type.
46+
"""
47+
# Arrange
48+
data = DYDXOraclePrice(instrument_id=instrument_id, price=Decimal(5), ts_init=5, ts_event=6)
49+
50+
# Act
51+
data_dict = data.to_dict()
52+
data_from_dict = DYDXOraclePrice.from_dict(data_dict)
53+
54+
# Assert
55+
assert data.instrument_id == data_from_dict.instrument_id
56+
assert data.price == data_from_dict.price
57+
assert data.ts_event == data_from_dict.ts_event
58+
assert data.ts_init == data_from_dict.ts_init

0 commit comments

Comments
 (0)