Skip to content

Commit

Permalink
use erc20_token_info in contract tester
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Sep 30, 2024
1 parent 2d416bf commit 3718622
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 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.21.7" }
thiserror = { version = "1.0.31" }
protobuf = { version = "3.2.0", features = ["with-bytes"] }
cw20 = "1.1.2"

[dev-dependencies]
cosmwasm-schema = "1.0.0"
Expand Down
13 changes: 12 additions & 1 deletion contracts/sei-tester/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #[cfg(not(feature = "library"))]
use base64::{engine::general_purpose, Engine as _};
use cosmwasm_std::to_json_binary;
#[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 @@ -21,6 +21,7 @@ use sei_cosmwasm::{
OrderType, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuerier, SeiQueryWrapper,
SettlementEntry, StaticCallResponse, SudoMsg,
};
use cw20::{TokenInfoResponse};

const PLACE_ORDER_REPLY_ID: u64 = 1;
// version info for migration info
Expand Down Expand Up @@ -453,6 +454,10 @@ pub fn query(deps: Deps<SeiQueryWrapper>, _env: Env, msg: QueryMsg) -> StdResult
QueryMsg::GetSeiAddressByEvmAddress { evm_address } => {
to_json_binary(&query_sei_address(deps, evm_address)?)
}
QueryMsg::Erc20TokenInfo {
contract_address,
caller,
} => to_json_binary(&query_erc20_token_info(deps, contract_address, caller)?),
}
}

Expand Down Expand Up @@ -600,3 +605,9 @@ pub fn query_sei_address(

Ok(res)
}

fn query_erc20_token_info(deps: Deps<SeiQueryWrapper>, contract_address: String, caller: String) -> StdResult<TokenInfoResponse> {
let querier = SeiQuerier::new(&deps.querier);
let erc20_token_info = querier.erc20_token_info(contract_address, caller)?;
Ok(erc20_token_info)
}
6 changes: 5 additions & 1 deletion contracts/sei-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum ExecuteMsg {
value: Uint128,
to: String,
data: String,
},
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down Expand Up @@ -83,4 +83,8 @@ pub enum QueryMsg {
GetSeiAddressByEvmAddress {
evm_address: String,
},
Erc20TokenInfo {
contract_address: String,
caller: String,
},
}
26 changes: 26 additions & 0 deletions contracts/sei-tester/tests/sei_tester_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cosmwasm_std::{
QueryRequest, StdError, Storage, Uint128,
};
use cosmwasm_std::{BlockInfo, Uint64};
use cw20::TokenInfoResponse;
use cw_multi_test::{
App, BankKeeper, ContractWrapper, DistributionKeeper, Executor, FailingModule, Router,
StakeKeeper, WasmKeeper,
Expand Down Expand Up @@ -1039,3 +1040,28 @@ fn test_sei_address_query() {
};
assert_eq!(res, expected_res);
}

#[test]
fn test_erc20_token_info_query() {
let mut app = mock_app(init_default_balances, vec![]);
let sei_tester_addr = setup_test(&mut app);

let res: TokenInfoResponse = app
.wrap()
.query_wasm_smart(
sei_tester_addr.clone(),
&QueryMsg::Erc20TokenInfo {
contract_address: EVM_ADDRESS.to_string(),
caller: SEI_ADDRESS.to_string(),
},
)
.unwrap();

let expected_res = TokenInfoResponse {
name: "Erc20Token".to_string(),
symbol: "TT".to_string(),
decimals: 18,
total_supply: Uint128::new(1000000),
};
assert_eq!(res, expected_res);
}
1 change: 1 addition & 0 deletions packages/sei-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ serde = { version = "1.0.137", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
[dependencies]
base64 = "0.21.7"
cw20 = "1.1.2"
9 changes: 9 additions & 0 deletions packages/sei-integration-tests/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{
fmt::Debug,
ops::{Add, Div, Mul, Sub},
};
use cw20::TokenInfoResponse;

pub struct SeiModule {
epoch: Epoch,
Expand Down Expand Up @@ -199,6 +200,14 @@ impl Module for SeiModule {
SeiQuery::GetSeiAddress { evm_address } => {
Ok(to_json_binary(&get_sei_address(evm_address))?)
}
SeiQuery::Erc20TokenInfo { .. } => {
Ok(to_json_binary(&TokenInfoResponse {
name: "Erc20Token".to_string(),
symbol: "TT".to_string(),
decimals: 18,
total_supply: Uint128::new(1000000),
})?)
}
// TODO: Implement get denom authority metadata in integration tests
SeiQuery::DenomAuthorityMetadata { .. } => {
panic!("Denom Authority Metadata not implemented")
Expand Down

0 comments on commit 3718622

Please sign in to comment.