Skip to content

Commit

Permalink
working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Apr 8, 2024
1 parent 499b54e commit 1194562
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions contracts/sei-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
base64 = { version = "0.13.0" }
thiserror = { version = "1.0.31" }
protobuf = { version = "3.2.0", features = ["with-bytes"] }
ethaddr = "0.2.2"

[dev-dependencies]
cosmwasm-schema = "1.0.0"
Expand Down
8 changes: 6 additions & 2 deletions contracts/sei-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
};
use protobuf::Message;
use sei_cosmwasm::{BulkOrderPlacementsResponse, Cancellation, DenomAuthorityMetadataResponse, DenomUnit, DenomsFromCreatorResponse, DepositInfo, DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse, Metadata, MsgPlaceOrdersResponse, OracleTwapsResponse, Order, OrderSimulationResponse, OrderType, PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry, SudoMsg, EvmAddressResponse, SeiAddressResponse};
use ethaddr::Address;

const PLACE_ORDER_REPLY_ID: u64 = 1;
// version info for migration info
Expand Down Expand Up @@ -561,9 +562,12 @@ pub fn query_evm_address(

pub fn query_sei_address(
deps: Deps<SeiQueryWrapper>,
sei_address: String,
evm_address: String,
) -> StdResult<SeiAddressResponse> {
let valid_addr = deps.api.addr_validate(&sei_address)?;
let valid_addr = match Address::from_str_checksum(&*evm_address) {
Ok(addr) => addr,
Err(_) => return Err(StdError::generic_err("Failed to parse Ethereum address")),
};
let querier = SeiQuerier::new(&deps.querier);
let res = querier.get_sei_address(valid_addr.to_string())?;

Expand Down
26 changes: 19 additions & 7 deletions contracts/sei-tester/tests/sei_tester_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cw_multi_test::{
use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order, OrderSimulationResponse, OrderStatus, OrderType, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute};
use sei_integration_tests::{
helper::{get_balance, mock_app},
module::{SeiModule, EVM_ADDRESS, SEI_ADDRESS}
module::{SeiModule, EVM_ADDRESS, SEI_ADDRESS},
};
use sei_tester::{
contract::{execute, instantiate, query},
Expand Down Expand Up @@ -145,7 +145,7 @@ fn test_tokenfactory_integration_foundation() {
},
})],
)
.unwrap();
.unwrap();

let res: BalanceResponse = get_balance(&app, ADMIN.to_string(), out.to_string());
assert_eq!(res.amount.amount, Uint128::new(1));
Expand Down Expand Up @@ -178,7 +178,7 @@ fn test_tokenfactory_integration_foundation() {
},
})],
)
.unwrap();
.unwrap();

let res: BalanceResponse = get_balance(&app, ADMIN.to_string(), out.to_string());
assert_eq!(res.amount.amount, Uint128::new(0));
Expand Down Expand Up @@ -564,7 +564,7 @@ fn test_dex_module_query_order_simulation() {
contract_address: Addr::unchecked(&sei_tester_addr.to_string()),
})],
)
.unwrap();
.unwrap();

// Test all of sim order can be fulfilled
let res: OrderSimulationResponse = app
Expand Down Expand Up @@ -844,7 +844,7 @@ fn test_dex_module_query_dex_twap() {
contract_address: Addr::unchecked(&sei_tester_addr.to_string()),
})],
)
.unwrap();
.unwrap();

app.set_block(BlockInfo {
height: 2,
Expand Down Expand Up @@ -888,7 +888,7 @@ fn test_dex_module_query_dex_twap() {
contract_address: Addr::unchecked(&sei_tester_addr.to_string()),
})],
)
.unwrap();
.unwrap();

app.set_block(BlockInfo {
height: 3,
Expand Down Expand Up @@ -982,7 +982,7 @@ fn test_sei_address_query() {
let res: SeiAddressResponse = app
.wrap()
.query_wasm_smart(sei_tester_addr.clone(), &QueryMsg::GetSeiAddressByEvmAddress {
evm_address: "fake_address".to_string(),
evm_address: "0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E".to_string(),
})
.unwrap();

Expand All @@ -992,4 +992,16 @@ fn test_sei_address_query() {
};
assert_eq!(res, expected_res);

// Test error case when EVM address is invalid
let res: Result<SeiAddressResponse, StdError> = app
.wrap()
.query_wasm_smart(sei_tester_addr.clone(), &QueryMsg::GetSeiAddressByEvmAddress {
evm_address: "fakeaddress".to_string(),
});

assert!(res.is_err());

let err = res.expect_err("Expected an error because the EVM address is invalid");
assert_eq!(err.to_string(),
"Generic error: Querier contract error: Generic error: Failed to parse Ethereum address");
}
2 changes: 1 addition & 1 deletion packages/sei-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ pub struct SeiAddressResponse {

/// A boolean value indicating whether the SEI address is associated to EVM address.
pub associated: bool
}
}

0 comments on commit 1194562

Please sign in to comment.