Skip to content

Commit

Permalink
Merge pull request #3 from neutron-org/fix/update-cosmwasm
Browse files Browse the repository at this point in the history
feat: update cosmwasm, use neutron-sdk original repo as deps #ntrn-357
  • Loading branch information
pr0n00gler authored Aug 6, 2024
2 parents 023db0c + 8cf91fc commit 2679d29
Show file tree
Hide file tree
Showing 21 changed files with 303 additions and 124 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This repo contains [`neutron-test-tube`] which uses a delta of [`osmosis-test-tube`](https://github.com/osmosis-labs/test-tube/tree/main/packages/osmosis-test-tube) to enable testing against `neutron`.

Additionally, this repo contains [`test-tube-ntrn`](https://github.com/margined-protocol/test-tube/tree/main/packages/test-tube) the flavour of `test-tube` compatible with Neutron core chain.
Additionally, this repo contains [`test-tube-ntrn`](https://github.com/neutron-org/neutron-test-tube/tree/main/packages/test-tube) the flavour of `test-tube` compatible with Neutron core chain.

## Features

Expand Down
13 changes: 7 additions & 6 deletions packages/neutron-test-tube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "CosmWasm integration testing for Neutron"
edition = "2021"
license = "MIT OR Apache-2.0"
name = "neutron-test-tube"
repository = "https://github.com/margined-protocol/test-tube"
repository = "https://github.com/neutron-org/neutron-test-tube"
version = "4.0.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -12,19 +12,20 @@ exclude = [ "neutron", "test_artifacts" ]
[dependencies]
base64 = "0.21.5"
cosmrs = { version = "0.15.0", features = [ "cosmwasm", "rpc" ] }
cosmwasm-std = { version = "1.5.4", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] }
cosmwasm-std = { version = "2.0.4", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] }
hex = "0.4.2"
margined-neutron-std = { version = "4.0.1" }
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
neutron-sdk = { package = "neutron-sdk", git = "https://github.com/neutron-org/neutron-sdk", branch = "feat/remove-stargate" }
prost = "0.12.4"
serde = "1.0.144"
serde_json = "1.0.85"
test-tube-ntrn = { version = "0.1.0" }
test-tube-ntrn = { path = "../test-tube" }
thiserror = "1.0.34"

[build-dependencies]
bindgen = "0.60.1"

[dev-dependencies]
cw1-subkeys = "1.1.2"
cw1-whitelist = "1.1.2"
cw1-subkeys = "2.0.0"
cw1-whitelist = "2.0.0"
rayon = "1.5.3"
27 changes: 14 additions & 13 deletions packages/neutron-test-tube/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ let app = NeutronTestApp::new();
let accs = app
.init_accounts(
&[
Coin::new(1_000_000_000_000, "usdt"),
Coin::new(1_000_000_000_000, "untrn"),
Coin::new(1_000_000_000_000u128, "usdt"),
Coin::new(1_000_000_000_000u128, "untrn"),
],
2,
)
Expand All @@ -55,8 +55,8 @@ use neutron_test_tube::NeutronTestApp;
let app = NeutronTestApp::new();

let account = app.init_account(&[
Coin::new(1_000_000_000_000, "usdt"),
Coin::new(1_000_000_000_000, "untrn"),
Coin::new(1_000_000_000_000u128, "usdt"),
Coin::new(1_000_000_000_000u128, "untrn"),
]);
```

Expand All @@ -77,8 +77,8 @@ let app = NeutronTestApp::new();
let accs = app
.init_accounts(
&[
Coin::new(1_000_000_000_000, "usdt"),
Coin::new(1_000_000_000_000, "untrn"),
Coin::new(1_000_000_000_000u128, "usdt"),
Coin::new(1_000_000_000_000u128, "untrn"),
],
2,
)
Expand Down Expand Up @@ -113,8 +113,8 @@ let app = NeutronTestApp::new();
let accs = app
.init_accounts(
&[
Coin::new(1_000_000_000_000, "usdt"),
Coin::new(1_000_000_000_000, "untrn"),
Coin::new(1_000_000_000_000u128, "usdt"),
Coin::new(1_000_000_000_000u128, "untrn"),
],
2,
)
Expand Down Expand Up @@ -172,8 +172,8 @@ let app = NeutronTestApp::new();
let accs = app
.init_accounts(
&[
Coin::new(1_000_000_000_000, "usdt"),
Coin::new(1_000_000_000_000, "untrn"),
Coin::new(1_000_000_000_000u128, "usdt"),
Coin::new(1_000_000_000_000u128, "untrn"),
],
2,
)
Expand Down Expand Up @@ -250,13 +250,14 @@ Module wrappers provides convenient functions to interact with the appchain's mo
Let's try to interact with `Exchange` module:

```rust
#[allow(deprecated)]
use cosmwasm_std::Coin;
use margined_neutron_std::shim::Any;
use margined_neutron_std::types::{
use cosmos_sdk_proto::Any;
use cosmos_sdk_proto::{
cosmos::bank::v1beta1::{MsgSend, QueryBalanceRequest, SendAuthorization},
cosmos::base::v1beta1::Coin as BaseCoin,
neutron::dex as DexTypes,
};
use neutron_sdk::proto_types::neutron::dex as DexTypes;
use prost::Message;

use neutron_test_tube::{Account, Bank, Dex, NeutronTestApp};
Expand Down
4 changes: 2 additions & 2 deletions packages/neutron-test-tube/libntrntesttube/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/margined-protocol/test-tube/neutron-test-tube
module github.com/neutron-org/neutron-test-tube/neutron-test-tube

go 1.22.3

Expand All @@ -12,6 +12,7 @@ require (
github.com/cosmos/gogoproto v1.5.0
github.com/neutron-org/neutron/v4 v4.0.1
github.com/pkg/errors v0.9.1
github.com/skip-mev/slinky v1.0.3
)

require (
Expand Down Expand Up @@ -191,7 +192,6 @@ require (
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/skip-mev/block-sdk/v2 v2.1.2 // indirect
github.com/skip-mev/feemarket v1.0.3 // indirect
github.com/skip-mev/slinky v1.0.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand Down
31 changes: 25 additions & 6 deletions packages/neutron-test-tube/libntrntesttube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "C"

import (
// std
sdkmath "cosmossdk.io/math"
"encoding/base64"
"encoding/json"
"fmt"
Expand All @@ -17,9 +17,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/gogoproto/proto"
"github.com/margined-protocol/test-tube/neutron-test-tube/result"
"github.com/margined-protocol/test-tube/neutron-test-tube/testenv"
"github.com/neutron-org/neutron-test-tube/neutron-test-tube/result"
"github.com/neutron-org/neutron-test-tube/neutron-test-tube/testenv"
"github.com/pkg/errors"
slinkytypes "github.com/skip-mev/slinky/pkg/types"
oracletypes "github.com/skip-mev/slinky/x/oracle/types"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)
Expand Down Expand Up @@ -68,8 +70,6 @@ func InitTestEnv() uint64 { // Temp fix for concurrency issue

reqFinalizeBlock := abci.RequestFinalizeBlock{Height: env.Ctx.BlockHeight(), Txs: [][]byte{}, Time: newBlockTime}

// env.Ctx = env.App.NewContext(false)

env.App.FinalizeBlock(&reqFinalizeBlock)
env.App.Commit()

Expand Down Expand Up @@ -136,7 +136,6 @@ func IncreaseTime(envId uint64, seconds uint64) {
//export FinalizeBlock
func FinalizeBlock(envId uint64, base64ReqDeliverTx string) *C.char {
return internalFinalizeBlock(envId, base64ReqDeliverTx, 3)

}

func internalFinalizeBlock(envId uint64, base64ReqDeliverTx string, seconds uint64) *C.char {
Expand Down Expand Up @@ -381,6 +380,26 @@ func GetValidatorPrivateKey(envId uint64) *C.char {
return C.CString(base64Priv)
}

//export SetPriceForCurrencyPair
func SetPriceForCurrencyPair(envId uint64, base, quote string, price int64, blockTimestampSecs int64, blockHeight int64) *C.char {
env := loadEnv(envId)

env.App.OracleKeeper.SetPriceForCurrencyPair(
env.Ctx,
slinkytypes.CurrencyPair{
Base: base,
Quote: quote,
},
oracletypes.QuotePrice{
Price: sdkmath.NewInt(price),
BlockTimestamp: time.Unix(blockTimestampSecs, 0),
BlockHeight: uint64(blockHeight),
},
)

return C.CString("")
}

// ========= utils =========

func loadEnv(envId uint64) testenv.TestEnv {
Expand Down
17 changes: 3 additions & 14 deletions packages/neutron-test-tube/libntrntesttube/testenv/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func InitChain(appInstance *app.App) (sdk.Context, secp256k1.PrivKey) {

requireNoErr(err)

concensusParams := simtestutil.DefaultConsensusParams
concensusParams.Block = &tmproto.BlockParams{
consensusParams := simtestutil.DefaultConsensusParams
consensusParams.Block = &tmproto.BlockParams{
MaxBytes: 22020096,
MaxGas: -1,
}
Expand All @@ -123,7 +123,7 @@ func InitChain(appInstance *app.App) (sdk.Context, secp256k1.PrivKey) {
appInstance.InitChain(
&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: concensusParams,
ConsensusParams: consensusParams,
AppStateBytes: stateBytes,
ChainId: "neutron-666",
},
Expand Down Expand Up @@ -249,16 +249,6 @@ func (env *TestEnv) BeginNewBlock(executeNextEpoch bool, timeIncreaseSeconds uin
env.Ctx = env.App.NewContext(false)
}

// func (env *TestEnv) GetValidatorAddresses() []string {
// validators := env.App.StakingKeeper.GetAllValidators(env.Ctx)
// var addresses []string
// for _, validator := range validators {
// addresses = append(addresses, validator.OperatorAddress)
// }

// return addresses
// }

func (env *TestEnv) GetValidatorPrivateKey() []byte {
return env.Validator
}
Expand All @@ -279,7 +269,6 @@ func (env *TestEnv) FundAccount(ctx sdk.Context, bankKeeper bankkeeper.Keeper, a
if err := bankKeeper.MintCoins(ctx, dexmoduletypes.ModuleName, amounts); err != nil {
return err
}

return bankKeeper.SendCoinsFromModuleToAccount(ctx, dexmoduletypes.ModuleName, addr, amounts)
}

Expand Down
9 changes: 4 additions & 5 deletions packages/neutron-test-tube/src/module/authz.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use margined_neutron_std::types::cosmos::authz::v1beta1::{
use cosmos_sdk_proto::cosmos::authz::v1beta1::{
MsgExec, MsgExecResponse, MsgGrant, MsgGrantResponse, QueryGranteeGrantsRequest,
QueryGranteeGrantsResponse, QueryGranterGrantsRequest, QueryGranterGrantsResponse,
QueryGrantsRequest, QueryGrantsResponse,
Expand Down Expand Up @@ -45,16 +45,16 @@ where

#[cfg(test)]
mod tests {
use cosmwasm_std::Coin;
use margined_neutron_std::shim::Any;
use margined_neutron_std::types::{
use cosmos_sdk_proto::Any;
use cosmos_sdk_proto::{
cosmos::authz::v1beta1::{
GenericAuthorization, Grant, GrantAuthorization, MsgExec, MsgGrant,
QueryGranteeGrantsRequest, QueryGranterGrantsRequest,
},
cosmos::bank::v1beta1::{MsgSend, QueryBalanceRequest, SendAuthorization},
cosmos::base::v1beta1::Coin as BaseCoin,
};
use cosmwasm_std::Coin;
use prost::Message;

use crate::{Account, Authz, Bank, NeutronTestApp};
Expand Down Expand Up @@ -90,7 +90,6 @@ mod tests {
amount: 10u128.to_string(),
denom: "usdc".to_string(),
}],
allow_list: vec![],
},
&mut buf,
)
Expand Down
6 changes: 3 additions & 3 deletions packages/neutron-test-tube/src/module/bank.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use margined_neutron_std::types::cosmos::bank::v1beta1::{
use cosmos_sdk_proto::cosmos::bank::v1beta1::{
MsgSend, MsgSendResponse, QueryAllBalancesRequest, QueryAllBalancesResponse,
QueryBalanceRequest, QueryBalanceResponse, QueryTotalSupplyRequest, QueryTotalSupplyResponse,
};
Expand Down Expand Up @@ -40,9 +40,9 @@ where

#[cfg(test)]
mod tests {
use cosmos_sdk_proto::cosmos::bank::v1beta1::{MsgSend, QueryBalanceRequest};
use cosmos_sdk_proto::cosmos::base::v1beta1::Coin as BaseCoin;
use cosmwasm_std::Coin;
use margined_neutron_std::types::cosmos::bank::v1beta1::{MsgSend, QueryBalanceRequest};
use margined_neutron_std::types::cosmos::base::v1beta1::Coin as BaseCoin;

use crate::{Account, Bank, NeutronTestApp};
use test_tube_ntrn::Module;
Expand Down
24 changes: 24 additions & 0 deletions packages/neutron-test-tube/src/module/contractmanager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use neutron_sdk::proto_types::neutron::contractmanager::{QueryParamsRequest, QueryParamsResponse};
use test_tube_ntrn::fn_query;
use test_tube_ntrn::module::Module;
use test_tube_ntrn::runner::Runner;

#[allow(dead_code)]
pub struct Contractmanager<'a, R: Runner<'a>> {
runner: &'a R,
}

impl<'a, R: Runner<'a>> Module<'a, R> for Contractmanager<'a, R> {
fn new(runner: &'a R) -> Self {
Self { runner }
}
}

impl<'a, R> Contractmanager<'a, R>
where
R: Runner<'a>,
{
fn_query! {
pub query_params ["/neutron.contractmanager.Query/Params"]: QueryParamsRequest => QueryParamsResponse
}
}
4 changes: 2 additions & 2 deletions packages/neutron-test-tube/src/module/dex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use margined_neutron_std::types::neutron::dex as DexTypes;
use neutron_sdk::proto_types::neutron::dex as DexTypes;
use test_tube_ntrn::{fn_execute, fn_query};

use test_tube_ntrn::module::Module;
Expand Down Expand Up @@ -118,7 +118,7 @@ where
#[cfg(test)]
mod tests {
use cosmwasm_std::Coin;
use margined_neutron_std::types::neutron::dex as DexTypes;
use neutron_sdk::proto_types::neutron::dex as DexTypes;

use crate::{Account, Dex, NeutronTestApp};
use test_tube_ntrn::Module;
Expand Down
40 changes: 0 additions & 40 deletions packages/neutron-test-tube/src/module/gov.rs

This file was deleted.

Loading

0 comments on commit 2679d29

Please sign in to comment.