Skip to content

Commit

Permalink
draft working version of getting EVM address
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Apr 5, 2024
1 parent a2fb892 commit 0656824
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 78 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["packages/*", "contracts/*"]
resolver = "2"

[profile.release.package.sei-cosmwasm]
opt-level = 3
Expand Down
16 changes: 15 additions & 1 deletion contracts/sei-tester/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::to_json_binary;
#[cfg(not(feature = "library"))]
// #[cfg(not(feature = "library"))]
use cosmwasm_std::{
coin, entry_point, Attribute, BankMsg, Binary, Coin, Decimal, Deps, DepsMut, Env, MessageInfo,
Order as IteratorOrder, Reply, Response, StdError, StdResult, SubMsg, SubMsgResponse, Uint128,
Expand All @@ -18,6 +18,7 @@ use sei_cosmwasm::{
GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse, Metadata,
MsgPlaceOrdersResponse, OracleTwapsResponse, Order, OrderSimulationResponse, OrderType,
PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry, SudoMsg,
EvmAddressResponse
};

const PLACE_ORDER_REPLY_ID: u64 = 1;
Expand Down Expand Up @@ -436,6 +437,8 @@ pub fn query(deps: Deps<SeiQueryWrapper>, _env: Env, msg: QueryMsg) -> StdResult
QueryMsg::GetDenomsFromCreator { creator } => {
to_json_binary(&query_denoms_from_creator(deps, creator)?)
}
QueryMsg::GetEvmAddressBySeiAddress { sei_address } =>
to_json_binary(&query_evm_address(deps, sei_address)?),
}
}

Expand Down Expand Up @@ -549,3 +552,14 @@ pub fn query_denoms_from_creator(

Ok(res)
}

pub fn query_evm_address(
deps: Deps<SeiQueryWrapper>,
sei_address: String,
) -> StdResult<EvmAddressResponse> {
let valid_addr = deps.api.addr_validate(&sei_address)?;
let querier = SeiQuerier::new(&deps.querier);
let res = querier.get_evm_address(valid_addr.to_string())?;

Ok(res)
}
3 changes: 3 additions & 0 deletions contracts/sei-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ pub enum QueryMsg {
GetDenomsFromCreator {
creator: String,
},
GetEvmAddressBySeiAddress {
sei_address: String,
},
}
58 changes: 42 additions & 16 deletions contracts/sei-tester/tests/sei_tester_integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
use cosmwasm_std::{
coin, from_binary,
testing::{MockApi, MockStorage},
Addr, Api, BalanceResponse, Coin, CosmosMsg, Decimal, Empty, GovMsg, IbcMsg, IbcQuery,
QueryRequest, StdError, Storage, Uint128,
};
use cosmwasm_std::{Addr, Api, BalanceResponse, coin, Coin, CosmosMsg, Decimal, Empty, from_json, GovMsg, IbcMsg, IbcQuery, QueryRequest, StdError, Storage, testing::{MockApi, MockStorage}, Uint128};
use cosmwasm_std::{BlockInfo, Uint64};
use cw_multi_test::{
App, BankKeeper, ContractWrapper, DistributionKeeper, Executor, FailingModule, Router,
StakeKeeper, WasmKeeper,
};
use sei_cosmwasm::{
Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate,
OracleTwapsResponse, Order, OrderSimulationResponse, OrderStatus, OrderType, PositionDirection,
SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute, SudoMsg as SeiSudoMsg,
};

use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order, OrderSimulationResponse, OrderStatus, OrderType, PositionDirection, SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute};
use sei_integration_tests::{
helper::{get_balance, mock_app},
module::SeiModule,
module::{SeiModule, EVM_ADDRESS}
};
use sei_tester::{
contract::{execute, instantiate, query},
Expand Down Expand Up @@ -142,7 +133,7 @@ fn test_tokenfactory_integration_foundation() {
let res = arr.first().unwrap().clone().data;
let data = res.unwrap();

let out: String = from_binary(&data).unwrap();
let out: String = from_json(&data).unwrap();
assert_eq!(out.to_string(), "factory/admin/test");

app.execute_multi(
Expand Down Expand Up @@ -306,7 +297,7 @@ fn test_dex_module_integration_orders() {
.unwrap();
let res = arr.first().unwrap().clone().data;
let data = res.unwrap();
let out: String = from_binary(&data).unwrap();
let out: String = from_json(&data).unwrap();
assert_eq!(out.to_string(), contract_addr.to_string());

// Query GetOrders() after order 1
Expand Down Expand Up @@ -466,7 +457,7 @@ fn test_dex_module_integration_orders() {
.unwrap();
let res = arr.first().unwrap().clone().data;
let data = res.unwrap();
let out: String = from_binary(&data).unwrap();
let out: String = from_json(&data).unwrap();
assert_eq!(out.to_string(), contract_addr.to_string());

// Query GetOrders() after order 0 cancelled
Expand Down Expand Up @@ -931,3 +922,38 @@ fn test_dex_module_query_dex_twap() {

assert_eq!(res, expected_twap);
}

/// EVM Module - query EVM address
#[test]
fn test_evm_address_query() {
let mut app = mock_app(init_default_balances, vec![]);
let sei_tester_addr = setup_test(&mut app);

// Test associated EVM address
let res: EvmAddressResponse = app
.wrap()
.query_wasm_smart(sei_tester_addr.clone(), &QueryMsg::GetEvmAddressBySeiAddress {
sei_address: sei_tester_addr.to_string(),
})
.unwrap();

let expected_res = EvmAddressResponse {
evm_address: EVM_ADDRESS.to_string(),
associated: true,
};
assert_eq!(res, expected_res);

// Test non-associated EVM address
let res: EvmAddressResponse = app
.wrap()
.query_wasm_smart(sei_tester_addr.clone(), &QueryMsg::GetEvmAddressBySeiAddress {
sei_address: "fake_address".to_string(),
})
.unwrap();

let expected_res = EvmAddressResponse {
evm_address: String::new(),
associated: false,
};
assert_eq!(res, expected_res);
}
1 change: 1 addition & 0 deletions packages/sei-cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use query::{
DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
OracleTwapsResponse, OrderSimulationResponse, PriceResponse, SeiQuery, SeiQueryWrapper,
EvmAddressResponse
};
pub use route::SeiRoute;
pub use sei_types::{
Expand Down
Loading

0 comments on commit 0656824

Please sign in to comment.