diff --git a/packages/injective-test-tube/CHANGELOG.md b/packages/injective-test-tube/CHANGELOG.md index ae5dba1..b7b2d74 100644 --- a/packages/injective-test-tube/CHANGELOG.md +++ b/packages/injective-test-tube/CHANGELOG.md @@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.13.2-auction - 2024-08-10 + +### Changed + +- Updated to use `injective-std@v1.13.2-auction` which is a manual fix for the Auction protos + ## 1.13.2 - 2024-28-08 ### Changed + - Updated to use injective-core@v1.13.2 ## 1.13.0-3 - 2024-14-08 diff --git a/packages/injective-test-tube/Cargo.toml b/packages/injective-test-tube/Cargo.toml index d142b88..af3479f 100644 --- a/packages/injective-test-tube/Cargo.toml +++ b/packages/injective-test-tube/Cargo.toml @@ -4,7 +4,7 @@ edition = "2021" license = "MIT OR Apache-2.0" name = "injective-test-tube" repository = "https://github.com/InjectiveLabs/test-tube" -version = "1.13.2" +version = "1.13.2-auction" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html exclude = [ "injective-core", "test_artifacts" ] @@ -12,10 +12,11 @@ exclude = [ "injective-core", "test_artifacts" ] [dependencies] base64 = "0.21.5" cosmrs = { version = "0.15.0", features = [ "cosmwasm", "rpc" ] } +cosmwasm-schema = { version = "2.1.1" } cosmwasm-std = { version = "2.1.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "iterator", "stargate" ] } hex = "0.4.2" injective-cosmwasm = { version = "0.3.0" } -injective-std = { version = "1.13.0" } +injective-std = { version = "=1.13.2-auction" } prost = "0.12.3" serde = "1.0.144" serde_json = "1.0.85" diff --git a/packages/injective-test-tube/libinjectivetesttube/testenv/setup.go b/packages/injective-test-tube/libinjectivetesttube/testenv/setup.go index 32b3f76..15246d8 100644 --- a/packages/injective-test-tube/libinjectivetesttube/testenv/setup.go +++ b/packages/injective-test-tube/libinjectivetesttube/testenv/setup.go @@ -166,7 +166,6 @@ func GenesisStateWithValSet(appInstance *app.InjectiveApp) (app.GenesisState, se acc := authtypes.NewBaseAccountWithAddress(senderPrivKey.PubKey().Address().Bytes()) ////////////////////// - // balances := []banktypes.Balance{} balance := banktypes.Balance{ Address: acc.GetAddress().String(), Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100000000000000))), diff --git a/packages/injective-test-tube/src/module/auction.rs b/packages/injective-test-tube/src/module/auction.rs new file mode 100644 index 0000000..b10c9e8 --- /dev/null +++ b/packages/injective-test-tube/src/module/auction.rs @@ -0,0 +1,89 @@ +use injective_std::types::injective::auction::v1beta1::{ + QueryAuctionParamsRequest, QueryAuctionParamsResponse, QueryCurrentAuctionBasketRequest, + QueryCurrentAuctionBasketResponse, QueryLastAuctionResultRequest, + QueryLastAuctionResultResponse, QueryModuleStateRequest, QueryModuleStateResponse, +}; +use test_tube_inj::fn_query; + +use test_tube_inj::module::Module; +use test_tube_inj::runner::Runner; + +pub struct Auction<'a, R: Runner<'a>> { + runner: &'a R, +} + +impl<'a, R: Runner<'a>> Module<'a, R> for Auction<'a, R> { + fn new(runner: &'a R) -> Self { + Self { runner } + } +} + +impl<'a, R> Auction<'a, R> +where + R: Runner<'a>, +{ + fn_query! { + pub query_auction_params ["/injective.auction.v1beta1.Query/AuctionParams"]: QueryAuctionParamsRequest => QueryAuctionParamsResponse + } + + fn_query! { + pub query_current_auction_basket ["/injective.auction.v1beta1.Query/CurrentAuctionBasket"]: QueryCurrentAuctionBasketRequest => QueryCurrentAuctionBasketResponse + } + + fn_query! { + pub query_module_state ["/injective.auction.v1beta1.Query/ModuleState"]: QueryModuleStateRequest => QueryModuleStateResponse + } + + fn_query! { + pub query_last_auction_result ["/injective.auction.v1beta1.Query/LastAuctionResult"]: QueryLastAuctionResultRequest => QueryLastAuctionResultResponse + } +} + +#[cfg(test)] +mod tests { + use injective_std::types::{ + cosmos::base::v1beta1::Coin as BaseCoin, + injective::auction::v1beta1::{ + LastAuctionResult, Params, QueryAuctionParamsRequest, QueryLastAuctionResultRequest, + }, + }; + + use crate::{Auction, InjectiveTestApp}; + use test_tube_inj::Module; + + #[test] + fn auction_integration() { + let app = InjectiveTestApp::new(); + + let auction = Auction::new(&app); + + let response = auction + .query_auction_params(&QueryAuctionParamsRequest {}) + .unwrap(); + assert_eq!( + response.params, + Some(Params { + auction_period: 604800, + min_next_bid_increment_rate: 2_500_000_000_000_000u128.to_string() + }) + ); + + let response = auction + .query_last_auction_result(&QueryLastAuctionResultRequest {}) + .unwrap(); + assert!(response.last_auction_result.is_some()); + + let result = response.last_auction_result.unwrap(); + assert_eq!( + result, + LastAuctionResult { + amount: Some(BaseCoin { + denom: "inj".to_string(), + amount: "0".to_string() + }), + winner: "".to_string(), + round: 0u64, + } + ); + } +} diff --git a/packages/injective-test-tube/src/module/mod.rs b/packages/injective-test-tube/src/module/mod.rs index e8ba26d..e63044f 100644 --- a/packages/injective-test-tube/src/module/mod.rs +++ b/packages/injective-test-tube/src/module/mod.rs @@ -1,3 +1,4 @@ +mod auction; mod authz; mod bank; mod exchange; @@ -12,6 +13,7 @@ mod wasmx; pub use test_tube_inj::macros; pub use test_tube_inj::module::Module; +pub use auction::Auction; pub use authz::Authz; pub use bank::Bank; pub use exchange::Exchange; diff --git a/packages/injective-test-tube/src/module/oracle.rs b/packages/injective-test-tube/src/module/oracle.rs index 178b04d..8078068 100644 --- a/packages/injective-test-tube/src/module/oracle.rs +++ b/packages/injective-test-tube/src/module/oracle.rs @@ -138,8 +138,6 @@ mod tests { ) .unwrap(); - println!("{:#?}", res); - let proposal_id = res .events .iter() diff --git a/packages/test-tube/Cargo.toml b/packages/test-tube/Cargo.toml index d03b352..b98adbb 100644 --- a/packages/test-tube/Cargo.toml +++ b/packages/test-tube/Cargo.toml @@ -9,14 +9,13 @@ version = "2.0.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -base64 = "0.21.5" -cosmrs = { version = "0.15.0", features = [ "cosmwasm", "rpc" ] } -cosmwasm-std = { version = "2.1.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "iterator", "stargate" ] } -prost = "0.12.4" -serde = "1.0.144" -serde_json = "1.0.85" -tendermint-proto = "0.32.0" -thiserror = "1.0.34" +base64 = "0.21.5" +cosmrs = { version = "0.20.0", features = [ "cosmwasm", "rpc" ] } +cosmwasm-std = { version = "2.1.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "iterator", "stargate" ] } +prost = { version = "0.13.3", default-features = false, features = [ "prost-derive" ] } +serde = "1.0.144" +serde_json = "1.0.85" +thiserror = "1.0.34" [dev-dependencies] cw1-whitelist = "0.15.0" diff --git a/packages/test-tube/src/bindings.rs b/packages/test-tube/src/bindings.rs index 474504c..9afcce2 100644 --- a/packages/test-tube/src/bindings.rs +++ b/packages/test-tube/src/bindings.rs @@ -220,9 +220,6 @@ extern "C" { extern "C" { pub fn IncreaseTime(envId: GoUint64, seconds: GoInt64); } -extern "C" { - pub fn Execute(envId: GoUint64, base64ReqDeliverTx: GoString) -> *mut ::std::os::raw::c_char; -} extern "C" { pub fn Query( envId: GoUint64, diff --git a/packages/test-tube/src/runner/app.rs b/packages/test-tube/src/runner/app.rs index 025ff6d..776f786 100644 --- a/packages/test-tube/src/runner/app.rs +++ b/packages/test-tube/src/runner/app.rs @@ -6,14 +6,14 @@ use cosmrs::crypto::secp256k1::SigningKey; use cosmrs::proto::tendermint::v0_38::abci::ResponseFinalizeBlock; use cosmrs::tx; use cosmrs::tx::{Fee, SignerInfo}; -use cosmwasm_std::Coin; +use cosmwasm_std::{Coin, Timestamp}; use prost::Message; use crate::account::{Account, FeeSetting, SigningAccount}; use crate::bindings::{ - AccountNumber, AccountSequence, FinalizeBlock, GetBlockHeight, GetBlockTime, GetParamSet, - GetValidatorAddress, GetValidatorPrivateKey, IncreaseTime, InitAccount, InitTestEnv, Query, - Simulate, + AccountNumber, AccountSequence, CleanUp, FinalizeBlock, GetBlockHeight, GetBlockTime, + GetParamSet, GetValidatorAddress, GetValidatorPrivateKey, IncreaseTime, InitAccount, + InitTestEnv, Query, Simulate, }; use crate::redefine_as_go_string; use crate::runner::error::{DecodeError, EncodeError, RunnerError}; @@ -96,8 +96,6 @@ impl BaseApp { .map_err(DecodeError::Utf8Error)? .to_string(); - println!("pkey: {:?}", pkey); - let secp256k1_priv = BASE64_STANDARD .decode(pkey) .map_err(DecodeError::Base64DecodeError)?; @@ -105,7 +103,7 @@ impl BaseApp { let signing_key = SigningKey::from_slice(&secp256k1_priv).unwrap(); let validator = SigningAccount::new( - "inj".to_string(), + self.address_prefix.clone(), signing_key, FeeSetting::Auto { gas_price: Coin::new(INJECTIVE_MIN_GAS_PRICE, denom), @@ -116,6 +114,27 @@ impl BaseApp { Ok(validator) } + pub fn get_chain_id(&self) -> &str { + &self.chain_id + } + + pub fn get_account_sequence(&self, address: &str) -> u64 { + redefine_as_go_string!(address); + unsafe { AccountSequence(self.id, address) } + } + + pub fn get_account_number(&self, address: &str) -> u64 { + redefine_as_go_string!(address); + unsafe { AccountNumber(self.id, address) } + } + + /// Get the current block time + pub fn get_block_timestamp(&self) -> Timestamp { + let result = unsafe { GetBlockTime(self.id) }; + + Timestamp::from_nanos(result as u64) + } + /// Get the current block time pub fn get_block_time_nanos(&self) -> i64 { unsafe { GetBlockTime(self.id) } @@ -187,23 +206,23 @@ impl BaseApp { redefine_as_go_string!(addr); let seq = unsafe { AccountSequence(self.id, addr) }; - let account_number = unsafe { AccountNumber(self.id, addr) }; + let signer_info = SignerInfo::single_direct(Some(signer.public_key()), seq); + + let chain_id = self + .chain_id + .parse() + .expect("parse const str of chain id should never fail"); + let auth_info = signer_info.auth_info(fee); - let sign_doc = tx::SignDoc::new( - &tx_body, - &auth_info, - &(self - .chain_id - .parse() - .expect("parse const str of chain id should never fail")), - account_number, - ) - .map_err(|e| match e.downcast::() { - Ok(encode_err) => EncodeError::ProtoEncodeError(encode_err), - Err(e) => panic!("expect `prost::EncodeError` but got {:?}", e), - })?; + let sign_doc = + tx::SignDoc::new(&tx_body, &auth_info, &chain_id, account_number).map_err(|e| { + match e.downcast::() { + Ok(encode_err) => EncodeError::ProtoEncodeError(encode_err), + Err(e) => panic!("expect `prost::EncodeError` but got {:?}", e), + } + })?; let tx_raw = sign_doc.sign(signer.signing_key()).unwrap(); @@ -224,15 +243,7 @@ impl BaseApp { where I: IntoIterator, { - let zero_fee = Fee::from_amount_and_gas( - cosmrs::Coin { - denom: self.fee_denom.parse().unwrap(), - amount: INJECTIVE_MIN_GAS_PRICE, - }, - 0u64, - ); - - let tx = self.create_signed_tx(msgs, signer, zero_fee)?; + let tx = self.create_signed_tx(msgs, signer, self.default_simulation_fee())?; let base64_tx_bytes = BASE64_STANDARD.encode(tx); redefine_as_go_string!(base64_tx_bytes); @@ -246,6 +257,17 @@ impl BaseApp { .map_err(RunnerError::DecodeError) } } + + pub fn default_simulation_fee(&self) -> Fee { + Fee::from_amount_and_gas( + cosmrs::Coin { + denom: self.fee_denom.parse().unwrap(), + amount: INJECTIVE_MIN_GAS_PRICE, + }, + 0u64, + ) + } + fn estimate_fee(&self, msgs: I, signer: &SigningAccount) -> RunnerResult where I: IntoIterator, @@ -290,6 +312,15 @@ impl BaseApp { } } +/// Cleanup the test environment when the app is dropped. +impl Drop for BaseApp { + fn drop(&mut self) { + unsafe { + CleanUp(self.id); + } + } +} + impl<'a> Runner<'a> for BaseApp { fn execute_multiple( &self, diff --git a/packages/test-tube/src/runner/result.rs b/packages/test-tube/src/runner/result.rs index df94d94..bff905d 100644 --- a/packages/test-tube/src/runner/result.rs +++ b/packages/test-tube/src/runner/result.rs @@ -52,8 +52,8 @@ where .into_iter() .map(|a| -> Result { Ok(Attribute { - key: std::str::from_utf8(a.key.as_ref())?.to_string(), - value: std::str::from_utf8(a.value.as_ref())?.to_string(), + key: std::str::from_utf8(a.key_bytes())?.to_string(), + value: std::str::from_utf8(a.value_bytes())?.to_string(), }) }) .collect::, Utf8Error>>()?, @@ -102,8 +102,8 @@ where .into_iter() .map(|a| -> Result { Ok(Attribute { - key: a.key.to_string(), - value: a.value.to_string(), + key: std::str::from_utf8(a.key_bytes())?.to_string(), + value: std::str::from_utf8(a.value_bytes())?.to_string(), }) }) .collect::, Utf8Error>>()?,