From 5a015c11b00dfc3e76c0f546f8a7bd2315ce46f8 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 13 Jul 2022 14:44:27 +0300 Subject: [PATCH 01/10] TestBankMsgBurn --- .../internal/keeper/secret_contracts_test.go | 48 +++++++++++++++++-- .../testdata/test-contract/src/contract.rs | 8 ++-- .../v1-sanity-contract/src/contract.rs | 10 +++- .../testdata/v1-sanity-contract/src/msg.rs | 10 +++- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/x/compute/internal/keeper/secret_contracts_test.go b/x/compute/internal/keeper/secret_contracts_test.go index a35f1c3a2..b1b4e1265 100644 --- a/x/compute/internal/keeper/secret_contracts_test.go +++ b/x/compute/internal/keeper/secret_contracts_test.go @@ -3412,11 +3412,11 @@ func TestV010BankMsgSendFrom(t *testing.T) { var contractAddress sdk.AccAddress if callType == "init" { - contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","from":"%s","amount":[{"amount":"1","denom":"denom"}]}}`, walletB.String(), walletA.String()), false, false, defaultGasForTests, -1, sdk.NewCoins()) + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg_send":{"to":"%s","from":"%s","amount":[{"amount":"1","denom":"denom"}]}}`, walletB.String(), walletA.String()), false, false, defaultGasForTests, -1, sdk.NewCoins()) } else { contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, false, defaultGasForTests, -1, sdk.NewCoins()) - _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","from":"%s","amount":[{"amount":"1","denom":"denom"}]}}`, walletB.String(), walletA.String()), false, false, math.MaxUint64, 0) + _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg_send":{"to":"%s","from":"%s","amount":[{"amount":"1","denom":"denom"}]}}`, walletB.String(), walletA.String()), false, false, math.MaxUint64, 0) } require.NotEmpty(t, err) @@ -3496,11 +3496,11 @@ func TestBankMsgSend(t *testing.T) { var contractAddress sdk.AccAddress if callType == "init" { - contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","amount":%s}}`, walletB.String(), test.input), false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins(sdk.NewInt64Coin("denom", 2), sdk.NewInt64Coin("assaf", 2))) + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg_send":{"to":"%s","amount":%s}}`, walletB.String(), test.input), false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins(sdk.NewInt64Coin("denom", 2), sdk.NewInt64Coin("assaf", 2))) } else { contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins(sdk.NewInt64Coin("denom", 2), sdk.NewInt64Coin("assaf", 2))) - _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg":{"to":"%s","amount":%s}}`, walletB.String(), test.input), false, contract.IsCosmWasmV1, math.MaxUint64, 0) + _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg_send":{"to":"%s","amount":%s}}`, walletB.String(), test.input), false, contract.IsCosmWasmV1, math.MaxUint64, 0) } if test.isSuccuss { @@ -3522,6 +3522,46 @@ func TestBankMsgSend(t *testing.T) { } } +func TestBankMsgBurn(t *testing.T) { + t.Run("v1", func(t *testing.T) { + for _, callType := range []string{"init", "exec"} { + t.Run(callType, func(t *testing.T) { + for _, test := range []struct { + description string + sentFunds sdk.Coins + }{ + { + description: "try to burn coins it has", + sentFunds: sdk.NewCoins(sdk.NewInt64Coin("denom", 1)), + }, + { + description: "try to burn coins it doesnt have", + sentFunds: sdk.NewCoins(), + }, + } { + t.Run(test.description, func(t *testing.T) { + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) + + var err cosmwasm.StdError + var contractAddress sdk.AccAddress + + if callType == "init" { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"bank_msg_burn":{"amount":[{"amount":"1","denom":"denom"}]}}`), false, false, defaultGasForTests, -1, test.sentFunds) + } else { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, false, defaultGasForTests, -1, test.sentFunds) + + _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"bank_msg_burn":{"amount":[{"amount":"1","denom":"denom"}]}}`), false, false, math.MaxUint64, 0) + } + + require.NotEmpty(t, err) + require.Contains(t, err.Error(), "Unknown variant of Bank: invalid CosmosMsg from the contract") + }) + } + }) + } + }) +} + func TestV1ReplyOnMultipleSubmessages(t *testing.T) { ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) diff --git a/x/compute/internal/keeper/testdata/test-contract/src/contract.rs b/x/compute/internal/keeper/testdata/test-contract/src/contract.rs index ebb663ad0..d88404da5 100644 --- a/x/compute/internal/keeper/testdata/test-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/test-contract/src/contract.rs @@ -73,7 +73,7 @@ pub enum InitMsg { InitFromV1 { counter: u64, }, - BankMsg { + BankMsgSend { amount: Vec, to: HumanAddr, from: Option, @@ -169,7 +169,7 @@ pub enum HandleMsg { to: HumanAddr, from: HumanAddr, }, - BankMsg { + BankMsgSend { amount: Vec, to: HumanAddr, from: Option, @@ -419,7 +419,7 @@ pub fn init( log: vec![], }) } - InitMsg::BankMsg { + InitMsg::BankMsgSend { to, amount: coins, from, @@ -644,7 +644,7 @@ pub fn handle( log: vec![], data: None, }), - HandleMsg::BankMsg { to, amount, from } => Ok(HandleResponse { + HandleMsg::BankMsgSend { to, amount, from } => Ok(HandleResponse { messages: vec![CosmosMsg::Bank(BankMsg::Send { from_address: from.unwrap_or(env.contract.address), to_address: to, diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs index 0acc31b5e..4fa193380 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs @@ -144,12 +144,15 @@ pub fn instantiate( Ok(Response::new().add_attribute("c", format!("{}", answer))) } - InstantiateMsg::BankMsg { to, amount } => { + InstantiateMsg::BankMsgSend { to, amount } => { Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Send { to_address: to, amount, }))) } + InstantiateMsg::BankMsgBurn { amount } => { + Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Burn { amount }))) + } } } @@ -540,12 +543,15 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S return res; } - ExecuteMsg::BankMsg { to, amount } => { + ExecuteMsg::BankMsgSend { to, amount } => { Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Send { to_address: to, amount, }))) } + ExecuteMsg::BankMsgBurn { amount } => { + Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Burn { amount }))) + } } } diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs index 7236fa253..5b84876d0 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs @@ -59,10 +59,13 @@ pub enum InstantiateMsg { code_hash: String, msg: String, }, - BankMsg { + BankMsgSend { amount: Vec, to: String, }, + BankMsgBurn { + amount: Vec, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] @@ -262,10 +265,13 @@ pub enum ExecuteMsg { privkey: Binary, iterations: u32, }, - BankMsg { + BankMsgSend { amount: Vec, to: String, }, + BankMsgBurn { + amount: Vec, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] From df587360b530391b5a5f2c9bc0244055730ad2fe Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 13 Jul 2022 16:22:23 +0300 Subject: [PATCH 02/10] Rename enclave_cosmwasm_types to enclave_cosmwasm_v010_types --- cosmwasm/enclaves/Cargo.lock | 8 +++---- .../shared/contract-engine/Cargo.toml | 2 +- .../src/contract_operations.rs | 4 ++-- .../src/contract_validation.rs | 2 +- .../enclaves/shared/contract-engine/src/io.rs | 23 +++++++++---------- .../shared/contract-engine/src/query_chain.rs | 2 +- .../contract-engine/src/wasm/contract.rs | 2 +- .../enclaves/shared/cosmos-types/Cargo.toml | 13 ++++++----- .../shared/cosmos-types/src/multisig.rs | 2 +- .../shared/cosmos-types/src/single_address.rs | 2 +- .../shared/cosmos-types/src/traits.rs | 2 +- .../enclaves/shared/cosmos-types/src/types.rs | 2 +- .../Cargo.toml | 2 +- .../Makefile | 0 .../src/coins.rs | 0 .../src/consts.rs | 0 .../src/encoding.rs | 0 .../src/lib.rs | 0 .../src/math.rs | 0 .../src/query.rs | 0 .../src/std_error.rs | 0 .../src/system_error.rs | 0 .../src/types.rs | 2 -- .../shared/cosmwasm-v1-types/Cargo.toml | 2 +- .../src/results/cosmos_msg.rs | 2 +- .../cosmwasm-v1-types/src/results/events.rs | 2 +- .../cosmwasm-v1-types/src/results/response.rs | 2 +- .../src/results/submessages.rs | 2 +- 28 files changed, 38 insertions(+), 40 deletions(-) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/Cargo.toml (96%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/Makefile (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/coins.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/consts.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/encoding.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/lib.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/math.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/query.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/std_error.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/system_error.rs (100%) rename cosmwasm/enclaves/shared/{cosmwasm-types => cosmwasm-v010-types}/src/types.rs (98%) diff --git a/cosmwasm/enclaves/Cargo.lock b/cosmwasm/enclaves/Cargo.lock index e84ce170f..26a972389 100644 --- a/cosmwasm/enclaves/Cargo.lock +++ b/cosmwasm/enclaves/Cargo.lock @@ -420,7 +420,7 @@ dependencies = [ "ed25519-zebra", "enclave-ffi-types", "enclave_cosmos_types", - "enclave_cosmwasm_types", + "enclave_cosmwasm_v010_types", "enclave_cosmwasm_v1_types", "enclave_crypto", "enclave_utils", @@ -449,7 +449,7 @@ dependencies = [ "cosmos_proto", "derive_more", "enclave-ffi-types", - "enclave_cosmwasm_types", + "enclave_cosmwasm_v010_types", "enclave_crypto", "log", "num_enum", @@ -461,7 +461,7 @@ dependencies = [ ] [[package]] -name = "enclave_cosmwasm_types" +name = "enclave_cosmwasm_v010_types" version = "1.2.4" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx?rev=dc7389e10817b078f289386b3b6a852ab6c4c021)", @@ -482,7 +482,7 @@ dependencies = [ "bech32", "derive_more", "enclave-ffi-types", - "enclave_cosmwasm_types", + "enclave_cosmwasm_v010_types", "log", "serde 1.0.118", "serde_json 1.0.60", diff --git a/cosmwasm/enclaves/shared/contract-engine/Cargo.toml b/cosmwasm/enclaves/shared/contract-engine/Cargo.toml index 240a5fa94..972de3966 100644 --- a/cosmwasm/enclaves/shared/contract-engine/Cargo.toml +++ b/cosmwasm/enclaves/shared/contract-engine/Cargo.toml @@ -23,7 +23,7 @@ enclave-ffi-types = { path = "../../ffi-types" } cosmos_proto = { path = "../cosmos-proto" } enclave_crypto = { path = "../crypto" } enclave_cosmos_types = { path = "../cosmos-types" } -enclave_cosmwasm_types = { path = "../cosmwasm-types" } +enclave_cosmwasm_v010_types = { path = "../cosmwasm-v010-types" } enclave_cosmwasm_v1_types = { path = "../cosmwasm-v1-types" } enclave_utils = { path = "../utils" } serde = { git = "https://github.com/mesalock-linux/serde-sgx", features = [ diff --git a/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs b/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs index 838e3fa7c..4a5ec1661 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs @@ -8,8 +8,8 @@ use crate::wasm::CosmWasmApiVersion; use cosmos_proto::tx::signing::SignMode; use cosmwasm_v010_types::types::CanonicalAddr; use enclave_cosmos_types::types::{ContractCode, HandleType, SigInfo}; -use enclave_cosmwasm_types as cosmwasm_v010_types; -use enclave_cosmwasm_types::encoding::Binary; +use enclave_cosmwasm_v010_types as cosmwasm_v010_types; +use enclave_cosmwasm_v010_types::encoding::Binary; use enclave_cosmwasm_v1_types::addresses::Addr; use enclave_cosmwasm_v1_types::results::{ DecryptedReply, Event, Reply, SubMsgResponse, SubMsgResult, diff --git a/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs b/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs index 77c30f2c0..3d8b09053 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/contract_validation.rs @@ -7,7 +7,7 @@ use enclave_cosmos_types::traits::CosmosAminoPubkey; use enclave_cosmos_types::types::{ ContractCode, CosmWasmMsg, CosmosPubKey, SigInfo, SignDoc, StdSignDoc, }; -use enclave_cosmwasm_types::types::{CanonicalAddr, Coin, Env, HumanAddr}; +use enclave_cosmwasm_v010_types::types::{CanonicalAddr, Coin, Env, HumanAddr}; use enclave_crypto::traits::VerifyingKey; use enclave_crypto::{sha_256, AESKey, Hmac, Kdf, HASH_SIZE, KEY_MANAGER}; diff --git a/cosmwasm/enclaves/shared/contract-engine/src/io.rs b/cosmwasm/enclaves/shared/contract-engine/src/io.rs index 8d691b98b..93a96adfe 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/io.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/io.rs @@ -5,9 +5,8 @@ use crate::contract_validation::ReplyParams; /// that is unique to the user and the enclave /// use super::types::{IoNonce, SecretMessage}; -use enclave_cosmwasm_types as cosmwasm_v010_types; -use enclave_cosmwasm_types::encoding::Binary; -use enclave_cosmwasm_types::types::{CanonicalAddr, Coin}; +use enclave_cosmwasm_v010_types::encoding::Binary; +use enclave_cosmwasm_v010_types::types::{CanonicalAddr, Coin}; use enclave_cosmwasm_v1_types::results::{Event, Reply, ReplyOn, SubMsgResponse, SubMsgResult}; use enclave_ffi_types::EnclaveError; @@ -43,7 +42,7 @@ enum RawWasmOutput { }, OkV010 { #[serde(rename = "Ok")] - ok: cosmwasm_v010_types::types::ContractResult, + ok: enclave_cosmwasm_v010_types::types::ContractResult, internal_reply_enclave_sig: Option, internal_msg_id: Option, }, @@ -58,7 +57,7 @@ enum RawWasmOutput { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] struct V010WasmOutput { #[serde(rename = "Ok")] - pub ok: Option, + pub ok: Option, #[serde(rename = "Err")] pub err: Option, } @@ -243,7 +242,7 @@ pub fn encrypt_output( internal_msg_id, } => { for msg in &mut ok.messages { - if let cosmwasm_v010_types::types::CosmosMsg::Wasm(wasm_msg) = msg { + if let enclave_cosmwasm_v010_types::types::CosmosMsg::Wasm(wasm_msg) = msg { encrypt_v010_wasm_msg( wasm_msg, secret_msg.nonce, @@ -496,20 +495,20 @@ pub fn encrypt_output( } fn encrypt_v010_wasm_msg( - wasm_msg: &mut cosmwasm_v010_types::types::WasmMsg, + wasm_msg: &mut enclave_cosmwasm_v010_types::types::WasmMsg, nonce: IoNonce, user_public_key: Ed25519PublicKey, contract_addr: &CanonicalAddr, ) -> Result<(), EnclaveError> { match wasm_msg { - cosmwasm_v010_types::types::WasmMsg::Execute { + enclave_cosmwasm_v010_types::types::WasmMsg::Execute { msg, callback_code_hash, callback_sig, send, .. } - | cosmwasm_v010_types::types::WasmMsg::Instantiate { + | enclave_cosmwasm_v010_types::types::WasmMsg::Instantiate { msg, callback_code_hash, callback_sig, @@ -590,11 +589,11 @@ fn encrypt_v1_wasm_msg( &msg_to_pass, &funds .iter() - .map(|coin| cosmwasm_v010_types::types::Coin { + .map(|coin| enclave_cosmwasm_v010_types::types::Coin { denom: coin.denom.clone(), - amount: cosmwasm_v010_types::math::Uint128(coin.amount.u128()), + amount: enclave_cosmwasm_v010_types::math::Uint128(coin.amount.u128()), }) - .collect::>()[..], + .collect::>()[..], )); } } diff --git a/cosmwasm/enclaves/shared/contract-engine/src/query_chain.rs b/cosmwasm/enclaves/shared/contract-engine/src/query_chain.rs index fe7a4e3b9..eec21d0bc 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/query_chain.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/query_chain.rs @@ -11,7 +11,7 @@ use super::errors::WasmEngineError; use crate::external::{ecalls, ocalls}; use crate::types::{IoNonce, SecretMessage}; -use enclave_cosmwasm_types::{ +use enclave_cosmwasm_v010_types::{ encoding::Binary, query::{QueryRequest, WasmQuery}, std_error::{StdError, StdResult}, diff --git a/cosmwasm/enclaves/shared/contract-engine/src/wasm/contract.rs b/cosmwasm/enclaves/shared/contract-engine/src/wasm/contract.rs index f31e76d82..efcd11a53 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/wasm/contract.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/wasm/contract.rs @@ -9,7 +9,7 @@ use wasmi::{Error as InterpreterError, MemoryInstance, MemoryRef, ModuleRef, Run use enclave_ffi_types::{Ctx, EnclaveError}; -use enclave_cosmwasm_types::consts::BECH32_PREFIX_ACC_ADDR; +use enclave_cosmwasm_v010_types::consts::BECH32_PREFIX_ACC_ADDR; use enclave_crypto::{sha_256, Ed25519PublicKey, WasmApiCryptoError}; use crate::contract_validation::ContractKey; diff --git a/cosmwasm/enclaves/shared/cosmos-types/Cargo.toml b/cosmwasm/enclaves/shared/cosmos-types/Cargo.toml index 52aaca70b..fa2c3417f 100644 --- a/cosmwasm/enclaves/shared/cosmos-types/Cargo.toml +++ b/cosmwasm/enclaves/shared/cosmos-types/Cargo.toml @@ -19,14 +19,15 @@ sgx_tstd = { rev = "a37ffb9449ba6d5b6e4a9d586bbab864ae732269", git = "https://gi cosmos_proto = { path = "../cosmos-proto" } enclave-ffi-types = { path = "../../ffi-types" } enclave_crypto = { path = "../crypto" } -enclave_cosmwasm_types = { path = "../cosmwasm-types" } - +enclave_cosmwasm_v010_types = { path = "../cosmwasm-v010-types" } log = "0.4.14" -serde = { git = "https://github.com/mesalock-linux/serde-sgx", features = ["derive"] } +serde = { git = "https://github.com/mesalock-linux/serde-sgx", features = [ + "derive" +] } derive_more = "0.99" - protobuf = "2.25.2" sha2 = "0.8.1" num_enum = "0.5.7" - -prost = { git = "https://github.com/mesalock-linux/prost-sgx", rev = "cd3103a6d45cf7a43b6c1c5e4223428097d1c547", default-features = false, features = ["prost-derive"] } +prost = { git = "https://github.com/mesalock-linux/prost-sgx", rev = "cd3103a6d45cf7a43b6c1c5e4223428097d1c547", default-features = false, features = [ + "prost-derive" +] } diff --git a/cosmwasm/enclaves/shared/cosmos-types/src/multisig.rs b/cosmwasm/enclaves/shared/cosmos-types/src/multisig.rs index dd78f9d80..daff4798b 100644 --- a/cosmwasm/enclaves/shared/cosmos-types/src/multisig.rs +++ b/cosmwasm/enclaves/shared/cosmos-types/src/multisig.rs @@ -10,7 +10,7 @@ use cosmos_proto::crypto::multisig::multisig::MultiSignature; use super::traits::CosmosAminoPubkey; -use enclave_cosmwasm_types::types::CanonicalAddr; +use enclave_cosmwasm_v010_types::types::CanonicalAddr; use enclave_crypto::CryptoError; use protobuf::Message; diff --git a/cosmwasm/enclaves/shared/cosmos-types/src/single_address.rs b/cosmwasm/enclaves/shared/cosmos-types/src/single_address.rs index 4ae7c7c54..7cdf08d6a 100644 --- a/cosmwasm/enclaves/shared/cosmos-types/src/single_address.rs +++ b/cosmwasm/enclaves/shared/cosmos-types/src/single_address.rs @@ -2,7 +2,7 @@ use enclave_crypto::secp256k1::{Secp256k1PubKey, SECP256K1_PREFIX}; use log::warn; use super::traits::CosmosAminoPubkey; -use enclave_cosmwasm_types::types::CanonicalAddr; +use enclave_cosmwasm_v010_types::types::CanonicalAddr; use enclave_crypto::hash::ripemd::ripemd160; use enclave_crypto::hash::sha::sha_256; diff --git a/cosmwasm/enclaves/shared/cosmos-types/src/traits.rs b/cosmwasm/enclaves/shared/cosmos-types/src/traits.rs index e722cc43f..97952c457 100644 --- a/cosmwasm/enclaves/shared/cosmos-types/src/traits.rs +++ b/cosmwasm/enclaves/shared/cosmos-types/src/traits.rs @@ -1,4 +1,4 @@ -use enclave_cosmwasm_types::types::CanonicalAddr; +use enclave_cosmwasm_v010_types::types::CanonicalAddr; // https://github.com/tendermint/tendermint/blob/v0.33.3/crypto/crypto.go#L22 pub trait CosmosAminoPubkey: PartialEq { diff --git a/cosmwasm/enclaves/shared/cosmos-types/src/types.rs b/cosmwasm/enclaves/shared/cosmos-types/src/types.rs index ac5528531..873a80733 100644 --- a/cosmwasm/enclaves/shared/cosmos-types/src/types.rs +++ b/cosmwasm/enclaves/shared/cosmos-types/src/types.rs @@ -12,7 +12,7 @@ use enclave_crypto::{ use cosmos_proto as proto; -use enclave_cosmwasm_types::{ +use enclave_cosmwasm_v010_types::{ coins::Coin, encoding::Binary, math::Uint128, diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/Cargo.toml b/cosmwasm/enclaves/shared/cosmwasm-v010-types/Cargo.toml similarity index 96% rename from cosmwasm/enclaves/shared/cosmwasm-types/Cargo.toml rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/Cargo.toml index 0e9152c8d..75c2e4b16 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-types/Cargo.toml +++ b/cosmwasm/enclaves/shared/cosmwasm-v010-types/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "enclave_cosmwasm_types" +name = "enclave_cosmwasm_v010_types" version = "1.2.4" authors = ["Cashmaney "] edition = "2018" diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/Makefile b/cosmwasm/enclaves/shared/cosmwasm-v010-types/Makefile similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/Makefile rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/Makefile diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/coins.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/coins.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/coins.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/coins.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/consts.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/consts.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/consts.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/consts.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/encoding.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/encoding.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/encoding.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/encoding.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/lib.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/lib.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/lib.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/lib.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/math.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/math.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/math.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/math.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/query.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/query.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/query.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/query.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/std_error.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/std_error.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/std_error.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/std_error.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/system_error.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/system_error.rs similarity index 100% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/system_error.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/system_error.rs diff --git a/cosmwasm/enclaves/shared/cosmwasm-types/src/types.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs similarity index 98% rename from cosmwasm/enclaves/shared/cosmwasm-types/src/types.rs rename to cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs index 6eca855d9..45de65343 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-types/src/types.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs @@ -148,8 +148,6 @@ where T: Clone + fmt::Debug + PartialEq, { Bank(BankMsg), - // by default we use RawMsg, but a contract can override that - // to call into more app-specific code (whatever they define) Custom(T), Staking(StakingMsg), Wasm(WasmMsg), diff --git a/cosmwasm/enclaves/shared/cosmwasm-v1-types/Cargo.toml b/cosmwasm/enclaves/shared/cosmwasm-v1-types/Cargo.toml index 111a79bd6..2fcbdc5a6 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v1-types/Cargo.toml +++ b/cosmwasm/enclaves/shared/cosmwasm-v1-types/Cargo.toml @@ -14,7 +14,7 @@ sgx_tstd = { rev = "a37ffb9449ba6d5b6e4a9d586bbab864ae732269", git = "https://gi [dependencies] enclave-ffi-types = { path = "../../ffi-types" } -enclave_cosmwasm_types = { path = "../cosmwasm-types" } +enclave_cosmwasm_v010_types = { path = "../cosmwasm-v010-types" } log = "0.4.8" serde = { git = "https://github.com/mesalock-linux/serde-sgx", features = [ "derive" diff --git a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/cosmos_msg.rs b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/cosmos_msg.rs index d0df5b032..f141bff5f 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/cosmos_msg.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/cosmos_msg.rs @@ -4,7 +4,7 @@ use std::fmt; use crate::coins::Coin; #[cfg(feature = "stargate")] use crate::ibc::IbcMsg; -use enclave_cosmwasm_types::encoding::Binary; +use enclave_cosmwasm_v010_types::encoding::Binary; use super::Empty; diff --git a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/events.rs b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/events.rs index 2ed0c637c..34e5e8450 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/events.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/events.rs @@ -1,4 +1,4 @@ -use enclave_cosmwasm_types::types::LogAttribute; +use enclave_cosmwasm_v010_types::types::LogAttribute; use serde::{Deserialize, Serialize}; /// A full [*Cosmos SDK* event]. /// diff --git a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/response.rs b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/response.rs index 9059963c9..1a6054a0c 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/response.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/response.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; -use enclave_cosmwasm_types::{encoding::Binary, types::LogAttribute}; +use enclave_cosmwasm_v010_types::{encoding::Binary, types::LogAttribute}; use super::{Empty, Event, SubMsg}; diff --git a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/submessages.rs b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/submessages.rs index 7b1d9cd83..b408467ff 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/submessages.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v1-types/src/results/submessages.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; -use enclave_cosmwasm_types::encoding::Binary; +use enclave_cosmwasm_v010_types::encoding::Binary; use super::{CosmosMsg, Empty, Event}; From f541956e1acccf587435adaf8b24af02411cc5f9 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 13 Jul 2022 16:46:56 +0300 Subject: [PATCH 03/10] Fix all contracts under cosmwasm/v010-contracts --- cosmwasm/Cargo.lock | 137 ++++++++++-------- cosmwasm/Cargo.toml | 2 +- .../shared/cosmwasm-v010-types/src/types.rs | 1 + cosmwasm/v010-contracts/burner/Cargo.lock | 87 ++++++++++- cosmwasm/v010-contracts/burner/Cargo.toml | 7 +- cosmwasm/v010-contracts/dist/Cargo.toml | 3 + cosmwasm/v010-contracts/erc20/Cargo.lock | 87 ++++++++++- cosmwasm/v010-contracts/erc20/Cargo.toml | 3 + cosmwasm/v010-contracts/escrow/Cargo.lock | 87 ++++++++++- cosmwasm/v010-contracts/escrow/Cargo.toml | 3 + .../v010-contracts/escrow/src/contract.rs | 69 +++------ cosmwasm/v010-contracts/escrow/src/state.rs | 8 +- cosmwasm/v010-contracts/gov/Cargo.toml | 3 + cosmwasm/v010-contracts/hackatom/Cargo.lock | 87 ++++++++++- cosmwasm/v010-contracts/hackatom/Cargo.toml | 3 + cosmwasm/v010-contracts/mint/Cargo.toml | 3 + .../v010-contracts/plaintext-logs/Cargo.toml | 3 + cosmwasm/v010-contracts/queue/Cargo.lock | 87 ++++++++++- cosmwasm/v010-contracts/queue/Cargo.toml | 7 +- cosmwasm/v010-contracts/reflect/Cargo.lock | 87 ++++++++++- cosmwasm/v010-contracts/reflect/Cargo.toml | 7 +- cosmwasm/v010-contracts/staking/Cargo.toml | 7 +- 22 files changed, 652 insertions(+), 136 deletions(-) diff --git a/cosmwasm/Cargo.lock b/cosmwasm/Cargo.lock index 0b26f9e58..1072bc936 100644 --- a/cosmwasm/Cargo.lock +++ b/cosmwasm/Cargo.lock @@ -45,9 +45,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.64" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" dependencies = [ "addr2line", "cc", @@ -148,7 +148,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" name = "cosmwasm-schema" version = "0.16.0" dependencies = [ - "schemars 0.8.8", + "schemars 0.8.10", "serde_json", ] @@ -179,9 +179,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" dependencies = [ "libc", ] @@ -216,9 +216,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dyn-clone" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2626afccd7561a06cf1367e2950c4718ea04565e20fb5029b6c7d8ad09abcf" +checksum = "140206b78fb2bc3edbcfc9b5ccbd0b30699cfe8d348b8b31b330e47df5291a5a" [[package]] name = "enclave-ffi-types" @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "lazy_static" @@ -298,33 +298,34 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.119" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "lock_api" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ + "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap" @@ -338,12 +339,11 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" dependencies = [ "adler", - "autocfg", ] [[package]] @@ -358,9 +358,9 @@ dependencies = [ [[package]] name = "object" -version = "0.27.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "memchr", ] @@ -404,27 +404,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.15" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags", ] @@ -455,9 +455,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "schemars" @@ -472,12 +472,12 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b5a3c80cea1ab61f4260238409510e814e38b4b563c06044edf91e7dc070e3" +checksum = "1847b767a3d62d95cbf3d8a9f0e421cf57a0d8aa4f411d4b16525afb0284d4ed" dependencies = [ "dyn-clone", - "schemars_derive 0.8.8", + "schemars_derive 0.8.10", "serde", "serde_json", ] @@ -490,19 +490,19 @@ checksum = "11af7a475c9ee266cfaa9e303a47c830ebe072bf3101ab907a7b7b9d816fa01d" dependencies = [ "proc-macro2", "quote", - "serde_derive_internals", + "serde_derive_internals 0.25.0", "syn", ] [[package]] name = "schemars_derive" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ae4dce13e8614c46ac3c38ef1c0d668b101df6ac39817aebdaa26642ddae9b" +checksum = "af4d7e1b012cb3d9129567661a63755ea4b8a7386d339dc945ae187e403c6743" dependencies = [ "proc-macro2", "quote", - "serde_derive_internals", + "serde_derive_internals 0.26.0", "syn", ] @@ -527,15 +527,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a3381e03edd24287172047536f20cabde766e2cd3e65e6b00fb3af51c4f38d" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" [[package]] name = "serde" -version = "1.0.136" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" dependencies = [ "serde_derive", ] @@ -551,9 +551,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", @@ -571,11 +571,22 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ "itoa", "ryu", @@ -611,9 +622,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "snafu" @@ -645,13 +656,13 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.86" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -679,18 +690,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -699,9 +710,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] @@ -713,16 +724,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] -name = "unicode-width" -version = "0.1.9" +name = "unicode-ident" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-width" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "vec_map" diff --git a/cosmwasm/Cargo.toml b/cosmwasm/Cargo.toml index 3b88cbbb3..53324cc3f 100644 --- a/cosmwasm/Cargo.toml +++ b/cosmwasm/Cargo.toml @@ -1,3 +1,3 @@ [workspace] members = ["packages/*"] -exclude = ["packages/enclave-test", "enclaves"] +exclude = ["packages/enclave-test", "enclaves", "v010-contracts/*"] diff --git a/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs index 45de65343..5fe472d8c 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs @@ -161,6 +161,7 @@ where pub enum CustomMsg { Debug(String), Raw(Binary), + Empty {}, } impl Into> for CustomMsg { diff --git a/cosmwasm/v010-contracts/burner/Cargo.lock b/cosmwasm/v010-contracts/burner/Cargo.lock index 941fabe36..e931f328c 100644 --- a/cosmwasm/v010-contracts/burner/Cargo.lock +++ b/cosmwasm/v010-contracts/burner/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -160,14 +160,16 @@ name = "cosmwasm-sgx-vm" version = "0.10.0" dependencies = [ "base64 0.12.3", - "cosmwasm-std", "enclave-ffi-types", "hex", "lazy_static", "log", "memmap", + "num_cpus", "parity-wasm", + "parking_lot", "schemars 0.7.6", + "secret-cosmwasm-std", "serde", "serde_json", "sgx_types", @@ -282,6 +284,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.8" @@ -300,6 +311,16 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -335,6 +356,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.26.2" @@ -356,6 +387,31 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pest" version = "2.1.3" @@ -515,6 +571,25 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "secret-cosmwasm-std" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4b8fed972d924458d9c3c0e6c9fbf6c4c5e30655571e3d2b78be056d316e9" +dependencies = [ + "base64 0.11.0", + "schemars 0.7.6", + "serde", + "serde-json-wasm", + "snafu", +] + [[package]] name = "semver" version = "0.11.0" @@ -611,6 +686,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "snafu" version = "0.6.10" diff --git a/cosmwasm/v010-contracts/burner/Cargo.toml b/cosmwasm/v010-contracts/burner/Cargo.toml index dc0fb3cad..6cfe2cadd 100644 --- a/cosmwasm/v010-contracts/burner/Cargo.toml +++ b/cosmwasm/v010-contracts/burner/Cargo.toml @@ -33,7 +33,9 @@ cranelift = ["cosmwasm-vm/default-cranelift"] singlepass = ["cosmwasm-vm/default-singlepass"] [dependencies] -cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = ["iterator"] } +cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = [ + "iterator" +] } schemars = "0.7" serde = { version = "1.0.103", default-features = false, features = ["derive"] } snafu = { version = "0.6.3" } @@ -43,3 +45,6 @@ cosmwasm-vm = { path = "../../packages/sgx-vm", package = "cosmwasm-sgx-vm", def "iterator" ] } cosmwasm-schema = { path = "../../packages/schema" } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/dist/Cargo.toml b/cosmwasm/v010-contracts/dist/Cargo.toml index 302676f26..cdcc82255 100644 --- a/cosmwasm/v010-contracts/dist/Cargo.toml +++ b/cosmwasm/v010-contracts/dist/Cargo.toml @@ -35,3 +35,6 @@ cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0 cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" } schemars = "0.7" serde = { version = "1.0.103", default-features = false, features = ["derive"] } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/erc20/Cargo.lock b/cosmwasm/v010-contracts/erc20/Cargo.lock index d60e23947..4ae0d0cdf 100644 --- a/cosmwasm/v010-contracts/erc20/Cargo.lock +++ b/cosmwasm/v010-contracts/erc20/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -148,14 +148,16 @@ name = "cosmwasm-sgx-vm" version = "0.10.0" dependencies = [ "base64 0.12.3", - "cosmwasm-std", "enclave-ffi-types", "hex", "lazy_static", "log", "memmap", + "num_cpus", "parity-wasm", + "parking_lot", "schemars 0.7.6", + "secret-cosmwasm-std", "serde", "serde_json", "sgx_types", @@ -292,6 +294,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.8" @@ -310,6 +321,16 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -345,6 +366,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.26.2" @@ -366,6 +397,31 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pest" version = "2.1.3" @@ -525,6 +581,25 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "secret-cosmwasm-std" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4b8fed972d924458d9c3c0e6c9fbf6c4c5e30655571e3d2b78be056d316e9" +dependencies = [ + "base64 0.11.0", + "schemars 0.7.6", + "serde", + "serde-json-wasm", + "snafu", +] + [[package]] name = "semver" version = "0.11.0" @@ -621,6 +696,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "snafu" version = "0.6.10" diff --git a/cosmwasm/v010-contracts/erc20/Cargo.toml b/cosmwasm/v010-contracts/erc20/Cargo.toml index e403f08dd..1be278387 100644 --- a/cosmwasm/v010-contracts/erc20/Cargo.toml +++ b/cosmwasm/v010-contracts/erc20/Cargo.toml @@ -45,3 +45,6 @@ hex = "0.4" [dev-dependencies] cosmwasm-vm = { path = "../../packages/sgx-vm", package = "cosmwasm-sgx-vm", default-features = false } cosmwasm-schema = { path = "../../packages/schema" } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/escrow/Cargo.lock b/cosmwasm/v010-contracts/escrow/Cargo.lock index 30922b8e4..5a2e750af 100644 --- a/cosmwasm/v010-contracts/escrow/Cargo.lock +++ b/cosmwasm/v010-contracts/escrow/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -148,14 +148,16 @@ name = "cosmwasm-sgx-vm" version = "0.10.0" dependencies = [ "base64 0.12.3", - "cosmwasm-std", "enclave-ffi-types", "hex", "lazy_static", "log", "memmap", + "num_cpus", "parity-wasm", + "parking_lot", "schemars 0.7.6", + "secret-cosmwasm-std", "serde", "serde_json", "sgx_types", @@ -291,6 +293,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.8" @@ -309,6 +320,16 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -344,6 +365,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.26.2" @@ -365,6 +396,31 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pest" version = "2.1.3" @@ -524,6 +580,25 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "secret-cosmwasm-std" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4b8fed972d924458d9c3c0e6c9fbf6c4c5e30655571e3d2b78be056d316e9" +dependencies = [ + "base64 0.11.0", + "schemars 0.7.6", + "serde", + "serde-json-wasm", + "snafu", +] + [[package]] name = "semver" version = "0.11.0" @@ -620,6 +695,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "snafu" version = "0.6.10" diff --git a/cosmwasm/v010-contracts/escrow/Cargo.toml b/cosmwasm/v010-contracts/escrow/Cargo.toml index a54bc6406..a09b5c68d 100644 --- a/cosmwasm/v010-contracts/escrow/Cargo.toml +++ b/cosmwasm/v010-contracts/escrow/Cargo.toml @@ -44,3 +44,6 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] } [dev-dependencies] cosmwasm-vm = { path = "../../packages/sgx-vm", package = "cosmwasm-sgx-vm", default-features = false } cosmwasm-schema = { path = "../../packages/schema" } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/escrow/src/contract.rs b/cosmwasm/v010-contracts/escrow/src/contract.rs index 0ed8d37b6..f636923ff 100644 --- a/cosmwasm/v010-contracts/escrow/src/contract.rs +++ b/cosmwasm/v010-contracts/escrow/src/contract.rs @@ -1,7 +1,6 @@ use cosmwasm_std::{ - generic_err, log, unauthorized, Api, BankMsg, Binary, CanonicalAddr, Coin, CosmosMsg, Env, - Extern, HandleResponse, HandleResult, InitResponse, InitResult, MigrateResponse, Querier, - StdResult, Storage, + log, Api, BankMsg, Binary, Coin, CosmosMsg, Env, Extern, HandleResponse, HandleResult, + HumanAddr, InitResponse, InitResult, MigrateResponse, Querier, StdError, StdResult, Storage, }; use crate::msg::{HandleMsg, InitMsg, MigrateMsg, QueryMsg}; @@ -13,14 +12,14 @@ pub fn init( msg: InitMsg, ) -> InitResult { let state = State { - arbiter: deps.api.canonical_address(&msg.arbiter)?, - recipient: deps.api.canonical_address(&msg.recipient)?, + arbiter: msg.arbiter.clone(), + recipient: msg.recipient.clone(), source: env.message.sender.clone(), end_height: msg.end_height, end_time: msg.end_time, }; if state.is_expired(&env) { - Err(generic_err("creating expired escrow")) + Err(StdError::generic_err("creating expired escrow")) } else { config(&mut deps.storage).save(&state)?; Ok(InitResponse::default()) @@ -46,28 +45,22 @@ fn try_approve( quantity: Option>, ) -> HandleResult { if env.message.sender != state.arbiter { - Err(unauthorized()) + Err(StdError::unauthorized()) } else if state.is_expired(&env) { - Err(generic_err("escrow expired")) + Err(StdError::generic_err("escrow expired")) } else { let amount = if let Some(quantity) = quantity { quantity } else { // release everything - let contract_address_human = deps.api.human_address(&env.contract.address)?; + let contract_address_human = env.contract.address.clone(); // Querier guarantees to returns up-to-date data, including funds sent in this handle message // https://github.com/CosmWasm/wasmd/blob/master/x/wasm/internal/keeper/keeper.go#L185-L192 deps.querier.query_all_balances(contract_address_human)? }; - send_tokens( - &deps.api, - &env.contract.address, - &state.recipient, - amount, - "approve", - ) + send_tokens(&env.contract.address, &state.recipient, amount, "approve") } } @@ -78,32 +71,25 @@ fn try_refund( ) -> HandleResult { // anyone can try to refund, as long as the contract is expired if !state.is_expired(&env) { - Err(generic_err("escrow not yet expired")) + Err(StdError::generic_err("escrow not yet expired")) } else { - let contract_address_human = deps.api.human_address(&env.contract.address)?; + let contract_address_human = env.contract.address.clone(); // Querier guarantees to returns up-to-date data, including funds sent in this handle message // https://github.com/CosmWasm/wasmd/blob/master/x/wasm/internal/keeper/keeper.go#L185-L192 let balance = deps.querier.query_all_balances(contract_address_human)?; - send_tokens( - &deps.api, - &env.contract.address, - &state.source, - balance, - "refund", - ) + send_tokens(&env.contract.address, &state.source, balance, "refund") } } // this is a helper to move the tokens, so the business logic is easy to read -fn send_tokens( - api: &A, - from_address: &CanonicalAddr, - to_address: &CanonicalAddr, +fn send_tokens( + from_address: &HumanAddr, + to_address: &HumanAddr, amount: Vec, action: &str, ) -> HandleResult { - let from_human = api.human_address(from_address)?; - let to_human = api.human_address(to_address)?; + let from_human = from_address.clone(); + let to_human = to_address.clone(); let log = vec![log("action", action), log("to", to_human.as_str())]; let r = HandleResponse { @@ -148,7 +134,7 @@ mod tests { height: u64, time: u64, ) -> Env { - let mut env = mock_env(api, signer, sent); + let mut env = mock_env(signer, sent); env.block.height = height; env.block.time = time; env @@ -168,18 +154,9 @@ mod tests { assert_eq!( state, State { - arbiter: deps - .api - .canonical_address(&HumanAddr::from("verifies")) - .unwrap(), - recipient: deps - .api - .canonical_address(&HumanAddr::from("benefits")) - .unwrap(), - source: deps - .api - .canonical_address(&HumanAddr::from("creator")) - .unwrap(), + arbiter: HumanAddr::from("verifies"), + recipient: HumanAddr::from("benefits"), + source: HumanAddr::from("creator"), end_height: Some(1000), end_time: None, } @@ -206,7 +183,7 @@ mod tests { // initialize the store let init_amount = coins(1000, "earth"); let init_env = mock_env_height(&deps.api, "creator", &init_amount, 876, 0); - let contract_addr = deps.api.human_address(&init_env.contract.address).unwrap(); + let contract_addr = init_env.contract.address.clone(); let msg = init_msg_expire_by_height(1000); let init_res = init(&mut deps, init_env, msg).unwrap(); assert_eq!(0, init_res.messages.len()); @@ -270,7 +247,7 @@ mod tests { // initialize the store let init_amount = coins(1000, "earth"); let init_env = mock_env_height(&deps.api, "creator", &init_amount, 876, 0); - let contract_addr = deps.api.human_address(&init_env.contract.address).unwrap(); + let contract_addr = init_env.contract.address.clone(); let msg = init_msg_expire_by_height(1000); let init_res = init(&mut deps, init_env, msg).unwrap(); assert_eq!(0, init_res.messages.len()); diff --git a/cosmwasm/v010-contracts/escrow/src/state.rs b/cosmwasm/v010-contracts/escrow/src/state.rs index 2f0298be8..5441210b8 100644 --- a/cosmwasm/v010-contracts/escrow/src/state.rs +++ b/cosmwasm/v010-contracts/escrow/src/state.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{CanonicalAddr, Env, Storage}; +use cosmwasm_std::{Env, HumanAddr, Storage}; use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -7,9 +7,9 @@ static CONFIG_KEY: &[u8] = b"config"; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct State { - pub arbiter: CanonicalAddr, - pub recipient: CanonicalAddr, - pub source: CanonicalAddr, + pub arbiter: HumanAddr, + pub recipient: HumanAddr, + pub source: HumanAddr, pub end_height: Option, pub end_time: Option, } diff --git a/cosmwasm/v010-contracts/gov/Cargo.toml b/cosmwasm/v010-contracts/gov/Cargo.toml index 3b1b83ee7..bf1e26db3 100644 --- a/cosmwasm/v010-contracts/gov/Cargo.toml +++ b/cosmwasm/v010-contracts/gov/Cargo.toml @@ -35,3 +35,6 @@ cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0 cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" } schemars = "0.7" serde = { version = "1", default-features = false, features = ["derive"] } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/hackatom/Cargo.lock b/cosmwasm/v010-contracts/hackatom/Cargo.lock index 621677a53..54eb99b46 100644 --- a/cosmwasm/v010-contracts/hackatom/Cargo.lock +++ b/cosmwasm/v010-contracts/hackatom/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -148,14 +148,16 @@ name = "cosmwasm-sgx-vm" version = "0.10.0" dependencies = [ "base64 0.12.3", - "cosmwasm-std", "enclave-ffi-types", "hex", "lazy_static", "log", "memmap", + "num_cpus", "parity-wasm", + "parking_lot", "schemars 0.7.6", + "secret-cosmwasm-std", "serde", "serde_json", "sgx_types", @@ -292,6 +294,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.8" @@ -310,6 +321,16 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -345,6 +366,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.26.2" @@ -366,6 +397,31 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pest" version = "2.1.3" @@ -525,6 +581,25 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "secret-cosmwasm-std" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4b8fed972d924458d9c3c0e6c9fbf6c4c5e30655571e3d2b78be056d316e9" +dependencies = [ + "base64 0.11.0", + "schemars 0.7.6", + "serde", + "serde-json-wasm", + "snafu", +] + [[package]] name = "semver" version = "0.11.0" @@ -621,6 +696,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "snafu" version = "0.6.10" diff --git a/cosmwasm/v010-contracts/hackatom/Cargo.toml b/cosmwasm/v010-contracts/hackatom/Cargo.toml index 10de2ed47..4f0ef68cd 100644 --- a/cosmwasm/v010-contracts/hackatom/Cargo.toml +++ b/cosmwasm/v010-contracts/hackatom/Cargo.toml @@ -37,3 +37,6 @@ sha2 = "0.9.1" cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" } cosmwasm-vm = { path = "../../packages/sgx-vm", package = "cosmwasm-sgx-vm", default-features = false } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/mint/Cargo.toml b/cosmwasm/v010-contracts/mint/Cargo.toml index 8bf5844e9..9b43a5b40 100644 --- a/cosmwasm/v010-contracts/mint/Cargo.toml +++ b/cosmwasm/v010-contracts/mint/Cargo.toml @@ -35,3 +35,6 @@ cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0 cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" } schemars = "0.7" serde = { version = "1.0.103", default-features = false, features = ["derive"] } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/plaintext-logs/Cargo.toml b/cosmwasm/v010-contracts/plaintext-logs/Cargo.toml index 1c5854b45..bed846772 100644 --- a/cosmwasm/v010-contracts/plaintext-logs/Cargo.toml +++ b/cosmwasm/v010-contracts/plaintext-logs/Cargo.toml @@ -33,4 +33,7 @@ backtraces = ["cosmwasm-std/backtraces"] cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", rev = "cf28ea21" } schemars = "0.7" serde = { version = "1.0.103", default-features = false, features = ["derive"] } + #snafu = { version = "0.6.3" } +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/queue/Cargo.lock b/cosmwasm/v010-contracts/queue/Cargo.lock index 03d9f6d8d..958aa8ba5 100644 --- a/cosmwasm/v010-contracts/queue/Cargo.lock +++ b/cosmwasm/v010-contracts/queue/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -148,14 +148,16 @@ name = "cosmwasm-sgx-vm" version = "0.10.0" dependencies = [ "base64 0.12.3", - "cosmwasm-std", "enclave-ffi-types", "hex", "lazy_static", "log", "memmap", + "num_cpus", "parity-wasm", + "parking_lot", "schemars 0.7.6", + "secret-cosmwasm-std", "serde", "serde_json", "sgx_types", @@ -270,6 +272,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.8" @@ -288,6 +299,16 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -323,6 +344,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.26.2" @@ -344,6 +375,31 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pest" version = "2.1.3" @@ -514,6 +570,25 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "secret-cosmwasm-std" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4b8fed972d924458d9c3c0e6c9fbf6c4c5e30655571e3d2b78be056d316e9" +dependencies = [ + "base64 0.11.0", + "schemars 0.7.6", + "serde", + "serde-json-wasm", + "snafu", +] + [[package]] name = "semver" version = "0.11.0" @@ -610,6 +685,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "snafu" version = "0.6.10" diff --git a/cosmwasm/v010-contracts/queue/Cargo.toml b/cosmwasm/v010-contracts/queue/Cargo.toml index b3229b5d7..05e8d994d 100644 --- a/cosmwasm/v010-contracts/queue/Cargo.toml +++ b/cosmwasm/v010-contracts/queue/Cargo.toml @@ -28,7 +28,9 @@ cranelift = ["cosmwasm-vm/default-cranelift"] singlepass = ["cosmwasm-vm/default-singlepass"] [dependencies] -cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = ["iterator"] } +cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = [ + "iterator" +] } schemars = "0.7" serde = { version = "1.0.103", default-features = false, features = ["derive"] } @@ -37,3 +39,6 @@ cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-vm = { path = "../../packages/sgx-vm", package = "cosmwasm-sgx-vm", default-features = false, features = [ "iterator" ] } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/reflect/Cargo.lock b/cosmwasm/v010-contracts/reflect/Cargo.lock index 16bb79d3f..0e1cd3dd0 100644 --- a/cosmwasm/v010-contracts/reflect/Cargo.lock +++ b/cosmwasm/v010-contracts/reflect/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -148,14 +148,16 @@ name = "cosmwasm-sgx-vm" version = "0.10.0" dependencies = [ "base64 0.12.3", - "cosmwasm-std", "enclave-ffi-types", "hex", "lazy_static", "log", "memmap", + "num_cpus", "parity-wasm", + "parking_lot", "schemars 0.7.6", + "secret-cosmwasm-std", "serde", "serde_json", "sgx_types", @@ -279,6 +281,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.8" @@ -297,6 +308,16 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -332,6 +353,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.26.2" @@ -353,6 +384,31 @@ version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "pest" version = "2.1.3" @@ -524,6 +580,25 @@ dependencies = [ "syn", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "secret-cosmwasm-std" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4b8fed972d924458d9c3c0e6c9fbf6c4c5e30655571e3d2b78be056d316e9" +dependencies = [ + "base64 0.11.0", + "schemars 0.7.6", + "serde", + "serde-json-wasm", + "snafu", +] + [[package]] name = "semver" version = "0.11.0" @@ -620,6 +695,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + [[package]] name = "snafu" version = "0.6.10" diff --git a/cosmwasm/v010-contracts/reflect/Cargo.toml b/cosmwasm/v010-contracts/reflect/Cargo.toml index ba0a1a9fb..49bd6b250 100644 --- a/cosmwasm/v010-contracts/reflect/Cargo.toml +++ b/cosmwasm/v010-contracts/reflect/Cargo.toml @@ -36,7 +36,9 @@ cranelift = ["cosmwasm-vm/default-cranelift"] singlepass = ["cosmwasm-vm/default-singlepass"] [dependencies] -cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = ["staking"] } +cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = [ + "staking" +] } cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" } schemars = "0.7" serde = { version = "^1.0.117", default-features = false, features = [ @@ -46,3 +48,6 @@ serde = { version = "^1.0.117", default-features = false, features = [ [dev-dependencies] cosmwasm-vm = { path = "../../packages/sgx-vm", package = "cosmwasm-sgx-vm", default-features = false } cosmwasm-schema = { path = "../../packages/schema" } + +[workspace] +members = [] diff --git a/cosmwasm/v010-contracts/staking/Cargo.toml b/cosmwasm/v010-contracts/staking/Cargo.toml index 6b7e7a29f..ef15e7cbd 100644 --- a/cosmwasm/v010-contracts/staking/Cargo.toml +++ b/cosmwasm/v010-contracts/staking/Cargo.toml @@ -30,8 +30,13 @@ overflow-checks = true backtraces = ["cosmwasm-std/backtraces"] [dependencies] -cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = ["staking"] } +cosmwasm-std = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print", features = [ + "staking" +] } cosmwasm-storage = { git = "https://github.com/enigmampc/SecretNetwork", tag = "v1.0.4-debug-print" } schemars = "0.7" serde = { version = "1.0.103", default-features = false, features = ["derive"] } snafu = { version = "0.6.3" } + +[workspace] +members = [] From 6ce26f984750933121fbcce4aa7b519d0bd70653 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 13 Jul 2022 18:35:19 +0300 Subject: [PATCH 04/10] Test CosmosMsg::Custom Plus remove reflect_test.go which will never be used that way because we never allow CustomMsg --- .../shared/cosmwasm-v010-types/src/types.rs | 23 +- x/compute/internal/keeper/reflect_test.go | 447 ------------------ .../internal/keeper/secret_contracts_test.go | 31 ++ x/compute/internal/keeper/staking_test.go | 20 + .../testdata/test-contract/src/contract.rs | 13 +- .../v1-sanity-contract/src/contract.rs | 8 +- .../testdata/v1-sanity-contract/src/msg.rs | 2 + 7 files changed, 80 insertions(+), 464 deletions(-) delete mode 100644 x/compute/internal/keeper/reflect_test.go diff --git a/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs index 5fe472d8c..54bb82dde 100644 --- a/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs +++ b/cosmwasm/enclaves/shared/cosmwasm-v010-types/src/types.rs @@ -143,7 +143,7 @@ pub struct ContractResult { #[serde(rename_all = "snake_case")] // This should be in correlation with cosmwasm-std/init_handle's CosmosMsg // See https://github.com/serde-rs/serde/issues/1296 why we cannot add De-Serialize trait bounds to T -pub enum CosmosMsg +pub enum CosmosMsg where T: Clone + fmt::Debug + PartialEq, { @@ -154,21 +154,14 @@ where Gov(GovMsg), } -/// Added this here for reflect tests.... +/// An empty struct that serves as a placeholder in different places, +/// such as contracts that don't set a custom message. +/// +/// It is designed to be expressable in correct JSON and JSON Schema but +/// contains no meaningful data. Previously we used enums without cases, +/// but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451) #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -#[serde(rename_all = "snake_case")] -/// CustomMsg is an override of CosmosMsg::Custom to show this works and can be extended in the contract -pub enum CustomMsg { - Debug(String), - Raw(Binary), - Empty {}, -} - -impl Into> for CustomMsg { - fn into(self) -> CosmosMsg { - CosmosMsg::Custom(self) - } -} +pub struct Empty {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "snake_case")] diff --git a/x/compute/internal/keeper/reflect_test.go b/x/compute/internal/keeper/reflect_test.go deleted file mode 100644 index 4a9866760..000000000 --- a/x/compute/internal/keeper/reflect_test.go +++ /dev/null @@ -1,447 +0,0 @@ -package keeper - -import ( - "encoding/hex" - "encoding/json" - "fmt" - "io/ioutil" - "strings" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - - wasmTypes "github.com/enigmampc/SecretNetwork/go-cosmwasm/types" - v010wasmTypes "github.com/enigmampc/SecretNetwork/go-cosmwasm/types/v010" - "github.com/enigmampc/SecretNetwork/x/compute/internal/types" -) - -// MaskInitMsg is {} - -// MaskHandleMsg is used to encode handle messages -type MaskHandleMsg struct { - Reflect *reflectPayload `json:"reflect_msg,omitempty"` - Change *ownerPayload `json:"change_owner,omitempty"` -} - -type ownerPayload struct { - Owner sdk.Address `json:"owner"` -} - -type reflectPayload struct { - Msgs []v010wasmTypes.CosmosMsg `json:"msgs"` -} - -// MaskQueryMsg is used to encode query messages -type MaskQueryMsg struct { - Owner *struct{} `json:"owner,omitempty"` - ReflectCustom *Text `json:"reflect_custom,omitempty"` -} - -type Text struct { - Text string `json:"text"` -} - -type OwnerResponse struct { - Owner string `json:"owner,omitempty"` -} - -const MaskFeatures = "staking,mask" - -func TestMaskReflectContractSend(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, MaskFeatures, reflectEncoders(MakeTestCodec()), nil) - accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper - - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - creator, privCreator := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, deposit) - _, _, bob := keyPubAddr() - - // upload mask code - maskCode, err := ioutil.ReadFile("./testdata/reflect.wasm") - require.NoError(t, err) - maskID, err := keeper.Create(ctx, creator, maskCode, "", "") - require.NoError(t, err) - require.Equal(t, uint64(1), maskID) - - // upload hackatom escrow code - escrowCode, err := ioutil.ReadFile("./testdata/contract.wasm") - require.NoError(t, err) - escrowID, err := keeper.Create(ctx, creator, escrowCode, "", "") - require.NoError(t, err) - require.Equal(t, uint64(2), escrowID) - - maskStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - - initMsgBz, err := testEncrypt(t, keeper, ctx, nil, maskID, []byte("{}")) - require.NoError(t, err) - - ctx = PrepareInitSignedTx(t, keeper, ctx, creator, privCreator, initMsgBz, maskID, maskStart) - - maskAddr, _, err := keeper.Instantiate(ctx, maskID, creator /* nil,*/, initMsgBz, "mask contract 2", maskStart, nil) - require.NoError(t, err) - require.NotEmpty(t, maskAddr) - - // now we set contract as verifier of an escrow - initMsg := InitMsg{ - Verifier: maskAddr, - Beneficiary: bob, - } - - initMsgBz, err = json.Marshal(initMsg) - require.NoError(t, err) - - initMsgBz, err = testEncrypt(t, keeper, ctx, nil, escrowID, initMsgBz) - require.NoError(t, err) - - escrowStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 25000)) - - ctx = PrepareInitSignedTx(t, keeper, ctx, creator, privCreator, initMsgBz, escrowID, escrowStart) - - escrowAddr, _, err := keeper.Instantiate(ctx, escrowID, creator /* nil,*/, initMsgBz, "escrow contract 2", escrowStart, nil) - - require.NoError(t, err) - require.NotEmpty(t, escrowAddr) - - // let's make sure all balances make sense - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, creator, sdk.NewCoins(sdk.NewInt64Coin("denom", 35000))) // 100k - 40k - 25k - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, maskAddr, maskStart) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, escrowAddr, escrowStart) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, bob, nil) - - // now for the trick.... we reflect a message through the mask to call the escrow - // we also send an additional 14k tokens there. - // this should reduce the mask balance by 14k (to 26k) - // this 14k is added to the escrow, then the entire balance is sent to bob (total: 39k) - - contractCodeHash := hex.EncodeToString(keeper.GetContractHash(ctx, escrowAddr)) - // approveMsg := []byte(contractCodeHash + `{"release":{}}`) - msgs := []v010wasmTypes.CosmosMsg{{ - Wasm: &v010wasmTypes.WasmMsg{ - Execute: &v010wasmTypes.ExecuteMsg{ - ContractAddr: escrowAddr.String(), - CallbackCodeHash: contractCodeHash, - Msg: []byte(`{"release":{}}`), - Send: []wasmTypes.Coin{{ - Denom: "denom", - Amount: "14000", - }}, - }, - }, - }} - reflectSend := MaskHandleMsg{ - Reflect: &reflectPayload{ - Msgs: msgs, - }, - } - reflectSendBz, err := json.Marshal(reflectSend) - require.NoError(t, err) - - reflectSendBz, err = testEncrypt(t, keeper, ctx, maskAddr, 0, reflectSendBz) - require.NoError(t, err) - - ctx = PrepareExecSignedTx(t, keeper, ctx, creator, privCreator, reflectSendBz, maskAddr, nil) - - _, err = keeper.Execute(ctx, maskAddr, creator, reflectSendBz, nil, nil) - require.NoError(t, err) - - // did this work??? - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, creator, sdk.NewCoins(sdk.NewInt64Coin("denom", 35000))) // same as before - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, maskAddr, sdk.NewCoins(sdk.NewInt64Coin("denom", 26000))) // 40k - 14k (from send) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, escrowAddr, sdk.Coins{}) // emptied reserved - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, bob, sdk.NewCoins(sdk.NewInt64Coin("denom", 39000))) // all escrow of 25k + 14k - -} - -func TestMaskReflectCustomMsg(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, MaskFeatures, reflectEncoders(MakeTestCodec()), reflectPlugins()) - accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper - - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - creator, privCreator := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, deposit) - bob, privBob := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, deposit) - _, _, fred := keyPubAddr() - - // upload code - maskCode, err := ioutil.ReadFile("./testdata/reflect.wasm") - require.NoError(t, err) - codeID, err := keeper.Create(ctx, creator, maskCode, "", "") - require.NoError(t, err) - require.Equal(t, uint64(1), codeID) - - // creator instantiates a contract and gives it tokens - initMsgBz, err := testEncrypt(t, keeper, ctx, nil, codeID, []byte("{}")) - require.NoError(t, err) - contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - ctx = PrepareInitSignedTx(t, keeper, ctx, creator, privCreator, initMsgBz, codeID, contractStart) - contractAddr, _, err := keeper.Instantiate(ctx, codeID, creator /* nil,*/, initMsgBz, "mask contract 1", contractStart, nil) - require.NoError(t, err) - require.NotEmpty(t, contractAddr) - - // set owner to bob - transfer := MaskHandleMsg{ - Change: &ownerPayload{ - Owner: bob, - }, - } - transferBz, err := json.Marshal(transfer) - require.NoError(t, err) - transferBz, err = testEncrypt(t, keeper, ctx, contractAddr, 0, transferBz) - require.NoError(t, err) - ctx = PrepareExecSignedTx(t, keeper, ctx, creator, privCreator, transferBz, contractAddr, nil) - _, err = keeper.Execute(ctx, contractAddr, creator, transferBz, nil, nil) - require.NoError(t, err) - - // check some account values - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, contractAddr, contractStart) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, bob, deposit) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, fred, nil) - - // bob can send contract's tokens to fred (using SendMsg) - msgs := []v010wasmTypes.CosmosMsg{{ - Bank: &v010wasmTypes.BankMsg{ - Send: &v010wasmTypes.SendMsg{ - FromAddress: contractAddr.String(), - ToAddress: fred.String(), - Amount: []wasmTypes.Coin{{ - Denom: "denom", - Amount: "15000", - }}, - }, - }, - }} - reflectSend := MaskHandleMsg{ - Reflect: &reflectPayload{ - Msgs: msgs, - }, - } - reflectSendBz, err := json.Marshal(reflectSend) - require.NoError(t, err) - reflectSendBz, err = testEncrypt(t, keeper, ctx, contractAddr, 0, reflectSendBz) - require.NoError(t, err) - ctx = PrepareExecSignedTx(t, keeper, ctx, bob, privBob, reflectSendBz, contractAddr, nil) - _, err = keeper.Execute(ctx, contractAddr, bob, reflectSendBz, nil, nil) - require.NoError(t, err) - - // fred got coins - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, fred, sdk.NewCoins(sdk.NewInt64Coin("denom", 15000))) - // contract lost them - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, contractAddr, sdk.NewCoins(sdk.NewInt64Coin("denom", 25000))) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, bob, deposit) - - // construct an opaque message - var sdkSendMsg sdk.Msg = &banktypes.MsgSend{ - FromAddress: contractAddr.String(), - ToAddress: fred.String(), - Amount: sdk.NewCoins(sdk.NewInt64Coin("denom", 23000)), - } - opaque, err := toReflectRawMsg(keeper.cdc, sdkSendMsg) - require.NoError(t, err) - reflectOpaque := MaskHandleMsg{ - Reflect: &reflectPayload{ - Msgs: []v010wasmTypes.CosmosMsg{opaque}, - }, - } - reflectOpaqueBz, err := json.Marshal(reflectOpaque) - require.NoError(t, err) - reflectOpaqueBz, err = testEncrypt(t, keeper, ctx, contractAddr, 0, reflectOpaqueBz) - require.NoError(t, err) - - ctx = PrepareExecSignedTx(t, keeper, ctx, bob, privBob, reflectOpaqueBz, contractAddr, nil) - _, err = keeper.Execute(ctx, contractAddr, bob, reflectOpaqueBz, nil, nil) - require.NoError(t, err) - - // fred got more coins - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, fred, sdk.NewCoins(sdk.NewInt64Coin("denom", 38000))) - // contract lost them - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, contractAddr, sdk.NewCoins(sdk.NewInt64Coin("denom", 2000))) - checkAccount(t, ctx, accKeeper, keeper.bankKeeper, bob, deposit) -} - -func TestMaskReflectCustomQuery(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, MaskFeatures, reflectEncoders(MakeTestCodec()), reflectPlugins()) - accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper - - deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) - creator, privCreator := CreateFakeFundedAccount(ctx, accKeeper, keeper.bankKeeper, deposit) - - // upload code - maskCode, err := ioutil.ReadFile("./testdata/reflect.wasm") - require.NoError(t, err) - codeID, err := keeper.Create(ctx, creator, maskCode, "", "") - require.NoError(t, err) - require.Equal(t, uint64(1), codeID) - - // creator instantiates a contract and gives it tokens - initMsgBz, err := testEncrypt(t, keeper, ctx, nil, codeID, []byte("{}")) - require.NoError(t, err) - contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - ctx = PrepareInitSignedTx(t, keeper, ctx, creator, privCreator, initMsgBz, codeID, contractStart) - contractAddr, _, err := keeper.Instantiate(ctx, codeID, creator /* nil,*/, initMsgBz, "mask contract 1", contractStart, nil) - require.NoError(t, err) - require.NotEmpty(t, contractAddr) - - // let's perform a normal query of state - ownerQuery := MaskQueryMsg{ - Owner: &struct{}{}, - } - ownerQueryBz, err := json.Marshal(ownerQuery) - require.NoError(t, err) - - ownerRes, qErr := queryHelper(t, keeper, ctx, contractAddr, string(ownerQueryBz), true, false, defaultGasForTests) - require.Empty(t, qErr) - var res OwnerResponse - err = json.Unmarshal([]byte(ownerRes), &res) - require.NoError(t, err) - assert.Equal(t, res.Owner, creator.String()) - - // and now making use of the custom querier callbacks - customQuery := MaskQueryMsg{ - ReflectCustom: &Text{ - Text: "all Caps noW", - }, - } - customQueryBz, err := json.Marshal(customQuery) - require.NoError(t, err) - - custom, qErr := queryHelper(t, keeper, ctx, contractAddr, string(customQueryBz), true, false, defaultGasForTests) - require.Empty(t, qErr) - - var resp customQueryResponse - err = json.Unmarshal([]byte(custom), &resp) - require.NoError(t, err) - assert.Equal(t, resp.Msg, "ALL CAPS NOW") -} - -func checkAccount(t *testing.T, ctx sdk.Context, accKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, expected sdk.Coins) { - acct := accKeeper.GetAccount(ctx, addr) - if expected == nil { - assert.Nil(t, acct) - } else { - assert.NotNil(t, acct) - coins := bankKeeper.GetAllBalances(ctx, acct.GetAddress()) - if expected.Empty() { - // there is confusion between nil and empty slice... let's just treat them the same - assert.True(t, coins.Empty()) - } else { - assert.Equal(t, coins, expected) - } - } -} - -/**** Code to support custom messages *****/ - -type reflectCustomMsg struct { - Debug string `json:"debug,omitempty"` - Raw []byte `json:"raw,omitempty"` -} - -// toReflectRawMsg encodes an sdk msg using any type with json encoding. -// Then wraps it as an opaque message -func toReflectRawMsg(cdc codec.BinaryCodec, msg sdk.Msg) (v010wasmTypes.CosmosMsg, error) { - any, err := codectypes.NewAnyWithValue(msg) - if err != nil { - return v010wasmTypes.CosmosMsg{}, err - } - rawBz, err := cdc.Marshal(any) - if err != nil { - return v010wasmTypes.CosmosMsg{}, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - customMsg, err := json.Marshal(reflectCustomMsg{ - Raw: rawBz, - }) - res := v010wasmTypes.CosmosMsg{ - Custom: customMsg, - } - return res, nil -} - -// reflectEncoders needs to be registered in test setup to handle custom message callbacks -func reflectEncoders(cdc codec.Codec) *MessageEncoders { - return &MessageEncoders{ - Custom: fromReflectRawMsg(cdc), - } -} - -// fromReflectRawMsg decodes msg.Data to an sdk.Msg using proto Any and json encoding. -// this needs to be registered on the Encoders -func fromReflectRawMsg(cdc codec.Codec) CustomEncoder { - return func(_sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) { - var custom reflectCustomMsg - err := json.Unmarshal(msg, &custom) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - if custom.Raw != nil { - var any codectypes.Any - if err := cdc.Unmarshal(custom.Raw, &any); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - var msg sdk.Msg - if err := cdc.UnpackAny(&any, &msg); err != nil { - return nil, err - } - return []sdk.Msg{msg}, nil - } - if custom.Debug != "" { - return nil, sdkerrors.Wrapf(types.ErrInvalidMsg, "Custom Debug: %s", custom.Debug) - } - return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown Custom message variant") - } -} - -type reflectCustomQuery struct { - Ping *struct{} `json:"ping,omitempty"` - Capital *Text `json:"capital,omitempty"` -} - -// this is from the go code back to the contract (capitalized or ping) -type customQueryResponse struct { - Msg string `json:"msg"` -} - -// these are the return values from contract -> go depending on type of query -type ownerResponse struct { - Owner string `json:"owner"` -} - -type capitalizedResponse struct { - Text string `json:"text"` -} - -type chainResponse struct { - Data []byte `json:"data"` -} - -// reflectPlugins needs to be registered in test setup to handle custom query callbacks -func reflectPlugins() *QueryPlugins { - return &QueryPlugins{ - Custom: performCustomQuery, - } -} - -func performCustomQuery(_ sdk.Context, request json.RawMessage) ([]byte, error) { - - var custom reflectCustomQuery - err := json.Unmarshal(request, &custom) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - fmt.Println(fmt.Sprintf("0x%02x", request)) - if custom.Capital != nil { - msg := strings.ToUpper(custom.Capital.Text) - return json.Marshal(customQueryResponse{Msg: msg}) - } - if custom.Ping != nil { - return json.Marshal(customQueryResponse{Msg: "pong"}) - } - - return nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown Custom query variant") -} diff --git a/x/compute/internal/keeper/secret_contracts_test.go b/x/compute/internal/keeper/secret_contracts_test.go index b1b4e1265..6042056f4 100644 --- a/x/compute/internal/keeper/secret_contracts_test.go +++ b/x/compute/internal/keeper/secret_contracts_test.go @@ -3562,6 +3562,37 @@ func TestBankMsgBurn(t *testing.T) { }) } +func TestCosmosMsgCustom(t *testing.T) { + for _, contract := range testContracts { + t.Run(contract.CosmWasmVersion, func(t *testing.T) { + for _, callType := range []string{"init", "exec"} { + t.Run(callType, func(t *testing.T) { + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, contract.WasmFilePath, sdk.NewCoins()) + + var err cosmwasm.StdError + var contractAddress sdk.AccAddress + + if callType == "init" { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, fmt.Sprintf(`{"cosmos_msg_custom":{}}`), false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins()) + } else { + contractAddress, _, err = initHelperImpl(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, false, contract.IsCosmWasmV1, defaultGasForTests, -1, sdk.NewCoins()) + + _, _, _, err = execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, fmt.Sprintf(`{"cosmos_msg_custom":{}}`), false, contract.IsCosmWasmV1, math.MaxUint64, 0) + } + + require.NotEmpty(t, err) + // if contract.IsCosmWasmV1 { + require.Contains(t, err.Error(), "Custom variant not supported: invalid CosmosMsg from the contract") + // } else { + // require.Equal(t, err.Error(), "Custom variant not supported: invalid CosmosMsg from the contract") + + // } + }) + } + }) + } +} + func TestV1ReplyOnMultipleSubmessages(t *testing.T) { ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/contract.wasm", sdk.NewCoins()) diff --git a/x/compute/internal/keeper/staking_test.go b/x/compute/internal/keeper/staking_test.go index 964770d65..fa0bf4361 100644 --- a/x/compute/internal/keeper/staking_test.go +++ b/x/compute/internal/keeper/staking_test.go @@ -48,6 +48,10 @@ type transferPayload struct { Amount string `json:"amount"` } +type ownerPayload struct { + Owner sdk.Address `json:"owner"` +} + type unbondPayload struct { // uint128 encoded as string Amount string `json:"amount"` @@ -243,6 +247,22 @@ func initializeStaking(t *testing.T) initInfo { } } +func checkAccount(t *testing.T, ctx sdk.Context, accKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, expected sdk.Coins) { + acct := accKeeper.GetAccount(ctx, addr) + if expected == nil { + assert.Nil(t, acct) + } else { + assert.NotNil(t, acct) + coins := bankKeeper.GetAllBalances(ctx, acct.GetAddress()) + if expected.Empty() { + // there is confusion between nil and empty slice... let's just treat them the same + assert.True(t, coins.Empty()) + } else { + assert.Equal(t, coins, expected) + } + } +} + func TestBonding(t *testing.T) { initInfo := initializeStaking(t) defer initInfo.cleanup() diff --git a/x/compute/internal/keeper/testdata/test-contract/src/contract.rs b/x/compute/internal/keeper/testdata/test-contract/src/contract.rs index d88404da5..91f14f27c 100644 --- a/x/compute/internal/keeper/testdata/test-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/test-contract/src/contract.rs @@ -1,7 +1,7 @@ use cosmwasm_storage::{PrefixedStorage, ReadonlySingleton, Singleton}; use cosmwasm_std::{ - log, to_binary, Api, BankMsg, Binary, Coin, CosmosMsg, Env, Extern, HandleResponse, + log, to_binary, Api, BankMsg, Binary, Coin, CosmosMsg, Empty, Env, Extern, HandleResponse, HandleResult, HumanAddr, InitResponse, InitResult, Querier, QueryRequest, QueryResult, ReadonlyStorage, StdError, StdResult, Storage, Uint128, WasmMsg, WasmQuery, }; @@ -78,6 +78,7 @@ pub enum InitMsg { to: HumanAddr, from: Option, }, + CosmosMsgCustom {}, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -265,6 +266,7 @@ pub enum HandleMsg { IncrementFromV1 { addition: u64, }, + CosmosMsgCustom {}, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -431,6 +433,10 @@ pub fn init( })], log: vec![], }), + InitMsg::CosmosMsgCustom {} => Ok(InitResponse { + messages: vec![CosmosMsg::Custom(Empty {})], + log: vec![], + }), } } @@ -653,6 +659,11 @@ pub fn handle( log: vec![], data: None, }), + HandleMsg::CosmosMsgCustom {} => Ok(HandleResponse { + messages: vec![CosmosMsg::Custom(Empty {})], + log: vec![], + data: None, + }), HandleMsg::SendFundsToInitCallback { amount, denom, diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs index 4fa193380..f609b2035 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs @@ -3,7 +3,7 @@ use mem::MaybeUninit; use std::{mem, thread}; use cosmwasm_std::{ - attr, coins, entry_point, to_binary, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, + attr, coins, entry_point, to_binary, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, QueryRequest, Reply, ReplyOn, Response, StdError, StdResult, Storage, SubMsg, SubMsgResult, WasmMsg, WasmQuery, }; @@ -153,6 +153,9 @@ pub fn instantiate( InstantiateMsg::BankMsgBurn { amount } => { Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Burn { amount }))) } + InstantiateMsg::CosmosMsgCustom {} => { + Ok(Response::new().add_message(CosmosMsg::Custom(Empty {}))) + } } } @@ -552,6 +555,9 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S ExecuteMsg::BankMsgBurn { amount } => { Ok(Response::new().add_message(CosmosMsg::Bank(BankMsg::Burn { amount }))) } + ExecuteMsg::CosmosMsgCustom {} => { + Ok(Response::new().add_message(CosmosMsg::Custom(Empty {}))) + } } } diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs index 5b84876d0..2e8fc7f76 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs @@ -66,6 +66,7 @@ pub enum InstantiateMsg { BankMsgBurn { amount: Vec, }, + CosmosMsgCustom {}, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] @@ -272,6 +273,7 @@ pub enum ExecuteMsg { BankMsgBurn { amount: Vec, }, + CosmosMsgCustom {}, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] From f8bdfede608da229e25e25ffa65355c91a87a61c Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 13 Jul 2022 20:08:09 +0300 Subject: [PATCH 05/10] Debug print in the CI, to fix TestLimitRecursiveQueryGas --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 97079d9df..08067e49a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -221,7 +221,7 @@ jobs: echo "not_a_key" > ias_keys/develop/spid.txt echo "not_a_key" > ias_keys/develop/api_key.txt LOG_LEVEL=ERROR go test -v ./x/compute/client/... - LOG_LEVEL=ERROR go test -p 1 -timeout 20m -v ./x/compute/internal/... + go test -p 1 -timeout 20m -v -run TestLimitRecursiveQueryGas ./x/compute/internal/... Clippy: runs-on: ubuntu-20.04 From d7b034c0a3b66e3f58f7be9eead810658575bae8 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Wed, 13 Jul 2022 20:57:13 +0300 Subject: [PATCH 06/10] CI: Remve LOG_LEVEL=ERROR form tests to try and debug why it fails --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 08067e49a..1371061b2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -220,8 +220,8 @@ jobs: mkdir -p /opt/secret/.sgx_secrets/ echo "not_a_key" > ias_keys/develop/spid.txt echo "not_a_key" > ias_keys/develop/api_key.txt - LOG_LEVEL=ERROR go test -v ./x/compute/client/... - go test -p 1 -timeout 20m -v -run TestLimitRecursiveQueryGas ./x/compute/internal/... + go test -v ./x/compute/client/... + go test -p 1 -timeout 20m -v ./x/compute/internal/... Clippy: runs-on: ubuntu-20.04 From 07d7a73e0ed438aa659762e9668e59b814bdd0cb Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 14 Jul 2022 08:52:35 +0300 Subject: [PATCH 07/10] Reverse the previous two commits Using `git diff 6ce26f984750933121fbcce4aa7b519d0bd70653 | git apply -R` --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1371061b2..97079d9df 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -220,8 +220,8 @@ jobs: mkdir -p /opt/secret/.sgx_secrets/ echo "not_a_key" > ias_keys/develop/spid.txt echo "not_a_key" > ias_keys/develop/api_key.txt - go test -v ./x/compute/client/... - go test -p 1 -timeout 20m -v ./x/compute/internal/... + LOG_LEVEL=ERROR go test -v ./x/compute/client/... + LOG_LEVEL=ERROR go test -p 1 -timeout 20m -v ./x/compute/internal/... Clippy: runs-on: ubuntu-20.04 From 1393181e8f4e5fbb9e6ca0a4af3bc9ad9efae5ec Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 14 Jul 2022 11:42:20 +0300 Subject: [PATCH 08/10] vscode settings --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index c85357f16..5c8358fe0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,9 +9,11 @@ "rust-analyzer.rustfmt.rangeFormatting.enable": true, "rust-analyzer.diagnostics.disabled": ["unresolved-macro-call"], "[rust]": { + "editor.formatOnSave": true, "editor.defaultFormatter": "rust-lang.rust-analyzer" }, + "go.formatTool": "gofumpt", "go.alternateTools": { " goreturns": "gofumpt" }, @@ -20,6 +22,7 @@ "RUST_BACKTRACE": "1" }, "[go]": { + "editor.formatOnSave": true, "editor.defaultFormatter": "golang.go" } } From fe35dc54dfe9192d724e5ee8a1ffc3c2f8907c92 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 14 Jul 2022 12:09:10 +0300 Subject: [PATCH 09/10] vscode settings gofumt --- .vscode/settings.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c8358fe0..244f2f6bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,14 +13,14 @@ "editor.defaultFormatter": "rust-lang.rust-analyzer" }, - "go.formatTool": "gofumpt", - "go.alternateTools": { - " goreturns": "gofumpt" - }, "go.testEnvVars": { "SGX_MODE": "SW", "RUST_BACKTRACE": "1" }, + "go.useLanguageServer": true, + "gopls": { + "formatting.gofumpt": true + }, "[go]": { "editor.formatOnSave": true, "editor.defaultFormatter": "golang.go" From b47841aba9ace6f15f66dc5dd3f8f738d9ae6331 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Thu, 14 Jul 2022 12:13:36 +0300 Subject: [PATCH 10/10] gofumpt -w . Co-authored-by: Jacob Gadikian --- app/app.go | 20 +++-- app/config.go | 75 +++++++++---------- app/export.go | 2 +- app/legacy/migrate.go | 3 +- app/legacy/v120/migrate.go | 1 + app/upgrades/v1.3/upgrades.go | 1 - cmd/secretd/attestation.go | 52 +++++++------ cmd/secretd/cli_attestation.go | 3 +- cmd/secretd/genaccounts.go | 12 +-- cmd/secretd/init.go | 2 +- cmd/secretd/root.go | 21 +++--- cmd/secretd/secret20.go | 33 ++++---- go-cosmwasm/api/callbacks.go | 7 +- go-cosmwasm/api/callbacks_cgo.go | 1 + go-cosmwasm/api/callbacks_cgo_mock.go | 1 + go-cosmwasm/api/callbacks_mock.go | 1 + go-cosmwasm/api/iterator.go | 3 +- go-cosmwasm/api/lib.go | 18 +++-- go-cosmwasm/api/lib_mock.go | 2 +- go-cosmwasm/api/link_muslc.go | 1 + go-cosmwasm/api/link_std.go | 1 + go-cosmwasm/api/memory.go | 3 +- go-cosmwasm/cmd/main.go | 3 +- go-cosmwasm/types/queries.go | 8 +- go-cosmwasm/types/queries_test.go | 3 +- go-cosmwasm/types/systemerror.go | 12 +-- types/util/prefix.go | 16 ++-- x/compute/client/cli/query.go | 8 +- x/compute/client/cli/tx.go | 6 +- x/compute/client/rest/tx.go | 5 +- x/compute/client/utils/utils.go | 2 +- x/compute/client/utils/utils_test.go | 10 ++- x/compute/handler.go | 1 - x/compute/internal/keeper/genesis.go | 4 +- x/compute/internal/keeper/gov_test.go | 4 +- x/compute/internal/keeper/handler_plugin.go | 24 +++--- .../internal/keeper/handler_plugin_test.go | 1 - x/compute/internal/keeper/ioutil.go | 3 +- x/compute/internal/keeper/ioutil_test.go | 1 - x/compute/internal/keeper/keeper.go | 17 ++--- x/compute/internal/keeper/keeper_test.go | 8 +- x/compute/internal/keeper/legacy_querier.go | 5 +- .../keeper/param_verification_test.go | 3 +- x/compute/internal/keeper/querier.go | 4 - x/compute/internal/keeper/querier_test.go | 2 +- x/compute/internal/keeper/query_plugins.go | 8 +- .../internal/keeper/secret_contracts_test.go | 2 +- x/compute/internal/keeper/test_common.go | 43 ++++++----- x/compute/internal/keeper/test_fuzz.go | 2 +- x/compute/internal/types/msg_test.go | 5 +- x/compute/internal/types/types.go | 9 ++- x/mauth/keeper/keeper_test.go | 3 +- x/mauth/keeper/msg_server_test.go | 1 - x/mauth/types/msgs.go | 5 +- x/registration/client/cli/query.go | 4 +- x/registration/client/cli/tx.go | 5 +- x/registration/client/rest/query.go | 4 +- x/registration/client/rest/tx.go | 6 +- x/registration/handler.go | 1 + x/registration/internal/keeper/genesis.go | 2 +- .../internal/keeper/genesis_test.go | 7 +- x/registration/internal/keeper/keeper.go | 5 +- x/registration/internal/keeper/keeper_test.go | 14 ++-- .../internal/keeper/legacy_querier.go | 3 +- x/registration/internal/keeper/querier.go | 1 + .../internal/keeper/querier_test.go | 7 +- .../internal/keeper/registration.go | 6 +- x/registration/internal/keeper/test_common.go | 13 ++-- x/registration/internal/types/genesis.go | 1 - x/registration/internal/types/msg_test.go | 16 ++-- x/registration/internal/types/types.go | 22 +++--- x/registration/module.go | 3 +- .../remote_attestation/fuzz_test.go | 1 + x/registration/remote_attestation/ra_test.go | 6 +- .../remote_attestation/remote_attestation.go | 31 ++++---- 75 files changed, 324 insertions(+), 325 deletions(-) diff --git a/app/app.go b/app/app.go index d920bbd4b..326fddf9f 100644 --- a/app/app.go +++ b/app/app.go @@ -2,6 +2,10 @@ package app import ( "fmt" + "io" + "net/http" + "os" + "path/filepath" store "github.com/cosmos/cosmos-sdk/store/types" @@ -94,11 +98,6 @@ import ( reg "github.com/enigmampc/SecretNetwork/x/registration" "github.com/spf13/cast" - "io" - "net/http" - "os" - "path/filepath" - "github.com/gorilla/mux" "github.com/rakyll/statik/fs" abci "github.com/tendermint/tendermint/abci/types" @@ -242,13 +241,12 @@ func NewSecretNetworkApp( skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, - //enabledProposals []compute.ProposalType, + // enabledProposals []compute.ProposalType, bootstrap bool, appOpts servertypes.AppOptions, computeConfig *compute.WasmConfig, baseAppOptions ...func(*baseapp.BaseApp), ) *SecretNetworkApp { - encodingConfig := MakeEncodingConfig() appCodec, legacyAmino := encodingConfig.Marshaler, encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry @@ -258,7 +256,7 @@ func NewSecretNetworkApp( bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) - //bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry) + // bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry) keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, @@ -447,7 +445,7 @@ func NewSecretNetworkApp( // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment // we prefer to be more strict in what arguments the modules expect. - var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. @@ -543,7 +541,7 @@ func NewSecretNetworkApp( govtypes.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, - //custom modules + // custom modules compute.ModuleName, reg.ModuleName, @@ -590,7 +588,7 @@ func NewSecretNetworkApp( // evidence.NewAppModule(app.evidenceKeeper), //) - //app.sm.RegisterStoreDecoders() + // app.sm.RegisterStoreDecoders() // initialize stores app.MountKVStores(keys) diff --git a/app/config.go b/app/config.go index bca32c030..fc2950fcf 100644 --- a/app/config.go +++ b/app/config.go @@ -52,44 +52,42 @@ import ( "github.com/enigmampc/SecretNetwork/x/registration" ) -var ( - mbasics = module.NewBasicManager( - append([]module.AppModuleBasic{ - authz.AppModuleBasic{}, - // accounts, fees. - auth.AppModuleBasic{}, - // genesis utilities - genutil.AppModuleBasic{}, - // tokens, token balance. - bank.AppModuleBasic{}, - capability.AppModuleBasic{}, - // validator staking - staking.AppModuleBasic{}, - // inflation - mint.AppModuleBasic{}, - // distribution of fess and inflation - distr.AppModuleBasic{}, - // governance functionality (voting) - gov.NewAppModuleBasic( - paramsclient.ProposalHandler, distrclient.ProposalHandler, - upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, - ), - // chain parameters - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - ibc.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - transfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - ica.AppModuleBasic{}, - }, - // our stuff - customModuleBasics()..., - )..., - ) +var mbasics = module.NewBasicManager( + append([]module.AppModuleBasic{ + authz.AppModuleBasic{}, + // accounts, fees. + auth.AppModuleBasic{}, + // genesis utilities + genutil.AppModuleBasic{}, + // tokens, token balance. + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + // validator staking + staking.AppModuleBasic{}, + // inflation + mint.AppModuleBasic{}, + // distribution of fess and inflation + distr.AppModuleBasic{}, + // governance functionality (voting) + gov.NewAppModuleBasic( + paramsclient.ProposalHandler, distrclient.ProposalHandler, + upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, + ), + // chain parameters + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + ibc.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + ica.AppModuleBasic{}, + }, + // our stuff + customModuleBasics()..., + )..., ) func customKVStoreKeys() []string { @@ -163,5 +161,4 @@ func transientStoreKeys() map[string]*sdk.TransientStoreKey { func memStoreKeys() map[string]*sdk.MemoryStoreKey { return sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) - } diff --git a/app/export.go b/app/export.go index e476ec61f..d1267e5bb 100644 --- a/app/export.go +++ b/app/export.go @@ -2,6 +2,7 @@ package app import ( "encoding/json" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -103,7 +104,6 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow // reinitialize all validators app.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - // donate any unwithdrawn outstanding reward fraction tokens to the community pool scraps := app.distrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) feePool := app.distrKeeper.GetFeePool(ctx) diff --git a/app/legacy/migrate.go b/app/legacy/migrate.go index 170ea8471..53cafd533 100644 --- a/app/legacy/migrate.go +++ b/app/legacy/migrate.go @@ -3,10 +3,11 @@ package legacy import ( "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/x/authz" "io/ioutil" "time" + "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/pkg/errors" "github.com/spf13/cobra" tmjson "github.com/tendermint/tendermint/libs/json" diff --git a/app/legacy/v120/migrate.go b/app/legacy/v120/migrate.go index c3409b114..1654f15aa 100644 --- a/app/legacy/v120/migrate.go +++ b/app/legacy/v120/migrate.go @@ -2,6 +2,7 @@ package legacy import ( "fmt" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" diff --git a/app/upgrades/v1.3/upgrades.go b/app/upgrades/v1.3/upgrades.go index 283f6bef5..41af2fca0 100644 --- a/app/upgrades/v1.3/upgrades.go +++ b/app/upgrades/v1.3/upgrades.go @@ -15,7 +15,6 @@ const UpgradeName = "v1.3" func CreateUpgradeHandler(mm *module.Manager, icamodule *icamodule.AppModule, configurator module.Configurator, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - // Assaf: Set version map for all modules because for some // reason it's not already set in upgradekeepr. // We upgrade from cosmos-sdk v0.44.5 to v0.45.4 and ibc-go v1.1.5 to v3.0.0 diff --git a/cmd/secretd/attestation.go b/cmd/secretd/attestation.go index 71be2f7d7..a9bc95ce9 100644 --- a/cmd/secretd/attestation.go +++ b/cmd/secretd/attestation.go @@ -9,6 +9,12 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io/ioutil" + "log" + "net/http" + "os" + "path/filepath" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -19,25 +25,25 @@ import ( reg "github.com/enigmampc/SecretNetwork/x/registration" ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation" "github.com/spf13/cobra" - "io/ioutil" - "log" - "net/http" - "os" - "path/filepath" ) -const flagReset = "reset" -const flagPulsar = "pulsar" -const flagCustomRegistrationService = "registration-service" +const ( + flagReset = "reset" + flagPulsar = "pulsar" + flagCustomRegistrationService = "registration-service" +) -const flagLegacyRegistrationNode = "registration-node" -const flagLegacyBootstrapNode = "node" +const ( + flagLegacyRegistrationNode = "registration-node" + flagLegacyBootstrapNode = "node" +) -const mainnetRegistrationService = "https://mainnet-register.scrtlabs.com/api/registernode" -const pulsarRegistrationService = "https://testnet-register.scrtlabs.com/api/registernode" +const ( + mainnetRegistrationService = "https://mainnet-register.scrtlabs.com/api/registernode" + pulsarRegistrationService = "https://testnet-register.scrtlabs.com/api/registernode" +) func InitAttestation() *cobra.Command { - cmd := &cobra.Command{ Use: "init-enclave [output-file]", Short: "Perform remote attestation of the enclave", @@ -47,7 +53,6 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert `, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - sgxSecretsDir := os.Getenv("SCRT_SGX_STORAGE") if sgxSecretsDir == "" { sgxSecretsDir = os.ExpandEnv("/opt/secret/.sgx_secrets") @@ -55,7 +60,7 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert // create sgx secrets dir if it doesn't exist if _, err := os.Stat(sgxSecretsDir); !os.IsNotExist(err) { - err := os.MkdirAll(sgxSecretsDir, 0777) + err := os.MkdirAll(sgxSecretsDir, 0o777) if err != nil { return err } @@ -109,7 +114,6 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert } func InitBootstrapCmd() *cobra.Command { - cmd := &cobra.Command{ Use: "init-bootstrap [node-exchange-file] [io-exchange-file]", Short: "Perform bootstrap initialization", @@ -224,7 +228,6 @@ func ParseCert() *cobra.Command { "register the node, during node initialization", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - // parse coins trying to be sent cert, err := ioutil.ReadFile(args[0]) if err != nil { @@ -251,7 +254,6 @@ func ConfigureSecret() *cobra.Command { "seed that was written on-chain", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - cert, err := ioutil.ReadFile(args[0]) if err != nil { return err @@ -287,7 +289,7 @@ func ConfigureSecret() *cobra.Command { seedFilePath := filepath.Join(nodeDir, reg.SecretNodeSeedConfig) - err = ioutil.WriteFile(seedFilePath, cfgBytes, 0664) + err = ioutil.WriteFile(seedFilePath, cfgBytes, 0o664) if err != nil { return err } @@ -306,7 +308,6 @@ func HealthCheck() *cobra.Command { Long: "Help diagnose issues by performing a basic sanity test that SGX is working properly", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - res, err := api.HealthCheck() if err != nil { return fmt.Errorf("failed to start enclave. Enclave returned: %s", err) @@ -328,7 +329,6 @@ func ResetEnclave() *cobra.Command { "You will have to go through registration again to be able to start the node", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - homeDir, err := cmd.Flags().GetString(flags.FlagHome) if err != nil { return err @@ -359,7 +359,7 @@ func ResetEnclave() *cobra.Command { if err != nil { return err } - err := os.MkdirAll(sgxSecretsDir, 0777) + err := os.MkdirAll(sgxSecretsDir, 0o777) if err != nil { return err } @@ -393,7 +393,6 @@ type ErrorResponse struct { // AutoRegisterNode *** EXPERIMENTAL *** func AutoRegisterNode() *cobra.Command { - cmd := &cobra.Command{ Use: "auto-register", Short: "Perform remote attestation of the enclave", @@ -402,7 +401,6 @@ Please report any issues with this command `, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - sgxSecretsFolder := os.Getenv("SCRT_SGX_STORAGE") if sgxSecretsFolder == "" { sgxSecretsFolder = os.ExpandEnv("/opt/secret/.sgx_secrets") @@ -552,7 +550,7 @@ Please report any issues with this command // create seed directory if it doesn't exist _, err = os.Stat(seedCfgDir) if os.IsNotExist(err) { - err = os.MkdirAll(seedCfgDir, 0777) + err = os.MkdirAll(seedCfgDir, 0o777) if err != nil { return fmt.Errorf("failed to create directory '%s': %w", seedCfgDir, err) } @@ -561,7 +559,7 @@ Please report any issues with this command // write seed to file - if file doesn't exist, write it. If it does, delete the existing one and create this _, err = os.Stat(seedCfgFile) if os.IsNotExist(err) { - err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0644) + err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0o644) if err != nil { return err } @@ -571,7 +569,7 @@ Please report any issues with this command return fmt.Errorf("failed to modify file '%s': %w", seedCfgFile, err) } - err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0644) + err = ioutil.WriteFile(seedCfgFile, cfgBytes, 0o644) if err != nil { return fmt.Errorf("failed to create file '%s': %w", seedCfgFile, err) } diff --git a/cmd/secretd/cli_attestation.go b/cmd/secretd/cli_attestation.go index 143b4cefb..3fcecb04c 100644 --- a/cmd/secretd/cli_attestation.go +++ b/cmd/secretd/cli_attestation.go @@ -1,3 +1,4 @@ +//go:build secretcli // +build secretcli package main @@ -9,7 +10,6 @@ import ( const flagReset = "reset" func InitAttestation() *cobra.Command { - cmd := &cobra.Command{ Use: "init-enclave [output-file]", Short: "Perform remote attestation of the enclave", @@ -29,7 +29,6 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert } func InitBootstrapCmd() *cobra.Command { - cmd := &cobra.Command{ Use: "init-bootstrap [node-exchange-file] [io-exchange-file]", Short: "Perform bootstrap initialization", diff --git a/cmd/secretd/genaccounts.go b/cmd/secretd/genaccounts.go index f9ec63813..e4bf9b8c7 100644 --- a/cmd/secretd/genaccounts.go +++ b/cmd/secretd/genaccounts.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -30,7 +31,6 @@ const ( // AddGenesisAccountCmd returns add-genesis-account cobra Command. func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command { - cmd := &cobra.Command{ Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]", Short: "Add a genesis account to genesis.json", @@ -183,11 +183,11 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa } cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - //cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") - //cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory") - //cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") - //cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") - //cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") + // cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") + // cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory") + // cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") + // cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") + // cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") flags.AddQueryFlagsToCmd(cmd) return cmd diff --git a/cmd/secretd/init.go b/cmd/secretd/init.go index a96665263..58c1f4225 100644 --- a/cmd/secretd/init.go +++ b/cmd/secretd/init.go @@ -92,7 +92,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { "ab6394e953e0b570bb1deeb5a8b387aa0dc6188a@scrt-seed-02.scrtlabs.com:26656", // SCRT Labs 2 "9cdaa5856e0245ecd73bd464308fb990fbc53b57@scrt-seed-03.scrtlabs.com:26656", // SCRT Labs 3 } - //Override default settings in config.toml + // Override default settings in config.toml config.P2P.Seeds = strings.Join(seeds[:], ",") } diff --git a/cmd/secretd/root.go b/cmd/secretd/root.go index 5cad82256..01db0b558 100644 --- a/cmd/secretd/root.go +++ b/cmd/secretd/root.go @@ -50,8 +50,11 @@ import ( // thanks @terra-project for this fix const flagLegacyHdPath = "legacy-hd-path" -const flagIsBootstrap = "bootstrap" -const cfgFileName = "config.toml" + +const ( + flagIsBootstrap = "bootstrap" + cfgFileName = "config.toml" +) var bootstrap bool @@ -91,7 +94,7 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { WithLegacyAmino(encodingConfig.Amino). WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). - //WithBroadcastMode(flags.BroadcastBlock). + // WithBroadcastMode(flags.BroadcastBlock). WithHomeDir(app.DefaultNodeHome). WithViper("SECRET") @@ -118,12 +121,12 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { secretAppTemplate, secretAppConfig := initAppConfig() - //ctx := server.GetServerContextFromCmd(cmd) + // ctx := server.GetServerContextFromCmd(cmd) - //bindFlags(cmd, ctx.Viper) + // bindFlags(cmd, ctx.Viper) return server.InterceptConfigsPreRunHandler(cmd, secretAppTemplate, secretAppConfig) - //return initConfig(&initClientCtx, cmd) + // return initConfig(&initClientCtx, cmd) }, SilenceUsage: true, } @@ -157,7 +160,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) { rootCmd.AddCommand( InitCmd(app.ModuleBasics(), app.DefaultNodeHome), - //updateTmParamsAndInit(app.ModuleBasics(), app.DefaultNodeHome), + // updateTmParamsAndInit(app.ModuleBasics(), app.DefaultNodeHome), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), secretlegacy.MigrateGenesisCmd(), genutilcli.GenTxCmd(app.ModuleBasics(), encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), @@ -245,7 +248,7 @@ func txCommand() *cobra.Command { authcmd.GetEncodeCommand(), authcmd.GetDecodeCommand(), flags.LineBreak, - //vestingcli.GetTxCmd(), + // vestingcli.GetTxCmd(), S20GetTxCmd(), ) @@ -310,7 +313,6 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty func exportAppStateAndTMValidators( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string, appOpts servertypes.AppOptions, ) (servertypes.ExportedApp, error) { - bootstrap := viper.GetBool("bootstrap") encCfg := app.MakeEncodingConfig() @@ -361,7 +363,6 @@ func initConfig(ctx *client.Context, cmd *cobra.Command) error { cmd.PersistentFlags().Bool(flagLegacyHdPath, false, "Flag to specify the command uses old HD path - use this for ledger compatibility") _, err := cmd.PersistentFlags().GetBool(flagLegacyHdPath) - if err != nil { return err } diff --git a/cmd/secretd/secret20.go b/cmd/secretd/secret20.go index cea3e5589..3a5663de7 100644 --- a/cmd/secretd/secret20.go +++ b/cmd/secretd/secret20.go @@ -6,6 +6,9 @@ import ( "encoding/json" "errors" "fmt" + "strconv" + "strings" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,12 +16,12 @@ import ( "github.com/enigmampc/SecretNetwork/x/compute/client/cli" "github.com/spf13/cobra" "github.com/spf13/viper" - "strconv" - "strings" ) -const MessageBlockSize = 256 -const flagAmount = "amount" +const ( + MessageBlockSize = 256 + flagAmount = "amount" +) // S20GetQueryCmd GetQueryCmd returns the cli query commands for this module func S20GetQueryCmd() *cobra.Command { @@ -69,7 +72,6 @@ func S20TransferHistoryCmd() *cobra.Command { Long: `Print out transfer you have been a part of - either as a sender or recipient`, Args: cobra.RangeArgs(3, 5), RunE: func(cmd *cobra.Command, args []string) error { - cliCtx, err := client.GetClientQueryContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -129,7 +131,6 @@ func S20TransactionHistoryCmd() *cobra.Command { Unlike the transfers query, this query shows all kinds of transactions with the contract.`, Args: cobra.RangeArgs(3, 5), RunE: func(cmd *cobra.Command, args []string) error { - cliCtx, err := client.GetClientQueryContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -189,7 +190,6 @@ func S20BalanceCmd() *cobra.Command { key yet, use the "create-viewing-key" command. Otherwise, you can still see your current balance using a raw transaction`, Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - cliCtx, err := client.GetClientQueryContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -246,7 +246,6 @@ func s20TransferCmd() *cobra.Command { Long: `Transfer tokens to another address`, Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - ////inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) @@ -288,8 +287,7 @@ func s20CreatingViewingKey() *cobra.Command { This way you can perform balance and transaction history queries without waiting for a transaction on-chain.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - - //inBuf := bufio.NewReader(cmd.InOrStdin()) + // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -327,8 +325,7 @@ func s20SetViewingKey() *cobra.Command { you're doing`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - - //inBuf := bufio.NewReader(cmd.InOrStdin()) + // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -357,8 +354,7 @@ func s20DepositCmd() *cobra.Command { Long: `Convert your SCRT into a secret token. This command will only work if the token supports native currency conversion`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - - //inBuf := bufio.NewReader(cmd.InOrStdin()) + // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -391,8 +387,7 @@ func s20Redeem() *cobra.Command { Long: `Convert your secret token back to SCRT. This command will only work if the token supports native currency conversion`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - - //inBuf := bufio.NewReader(cmd.InOrStdin()) + // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -428,8 +423,7 @@ func s20SendCmd() *cobra.Command { If no callback provided, this is identical to 'transfer'.`, Args: cobra.RangeArgs(3, 4), RunE: func(cmd *cobra.Command, args []string) error { - - //inBuf := bufio.NewReader(cmd.InOrStdin()) + // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) @@ -474,8 +468,7 @@ func s20BurnCmd() *cobra.Command { WARNING! This action is irreversible and permanent! use at your own risk`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - - //inBuf := bufio.NewReader(cmd.InOrStdin()) + // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) diff --git a/go-cosmwasm/api/callbacks.go b/go-cosmwasm/api/callbacks.go index 97a7f5fc4..315c56d72 100644 --- a/go-cosmwasm/api/callbacks.go +++ b/go-cosmwasm/api/callbacks.go @@ -1,3 +1,4 @@ +//go:build !secretcli // +build !secretcli package api @@ -302,8 +303,10 @@ func cNext(ref C.iterator_t, gasMeter *C.gas_meter_t, usedGas *C.uint64_t, key * /***** GoAPI *******/ -type HumanizeAddress func([]byte) (string, uint64, error) -type CanonicalizeAddress func(string) ([]byte, uint64, error) +type ( + HumanizeAddress func([]byte) (string, uint64, error) + CanonicalizeAddress func(string) ([]byte, uint64, error) +) type GoAPI struct { HumanAddress HumanizeAddress diff --git a/go-cosmwasm/api/callbacks_cgo.go b/go-cosmwasm/api/callbacks_cgo.go index 98a453e96..d734cc73f 100644 --- a/go-cosmwasm/api/callbacks_cgo.go +++ b/go-cosmwasm/api/callbacks_cgo.go @@ -1,3 +1,4 @@ +//go:build !secretcli // +build !secretcli package api diff --git a/go-cosmwasm/api/callbacks_cgo_mock.go b/go-cosmwasm/api/callbacks_cgo_mock.go index 56ef5102c..cafb234be 100644 --- a/go-cosmwasm/api/callbacks_cgo_mock.go +++ b/go-cosmwasm/api/callbacks_cgo_mock.go @@ -1,3 +1,4 @@ +//go:build secretcli // +build secretcli package api diff --git a/go-cosmwasm/api/callbacks_mock.go b/go-cosmwasm/api/callbacks_mock.go index 9a72c3fdb..56bc58aee 100644 --- a/go-cosmwasm/api/callbacks_mock.go +++ b/go-cosmwasm/api/callbacks_mock.go @@ -1,3 +1,4 @@ +//go:build secretcli // +build secretcli package api diff --git a/go-cosmwasm/api/iterator.go b/go-cosmwasm/api/iterator.go index 0d2fe8e68..352cef898 100644 --- a/go-cosmwasm/api/iterator.go +++ b/go-cosmwasm/api/iterator.go @@ -1,8 +1,9 @@ package api import ( - dbm "github.com/tendermint/tm-db" "sync" + + dbm "github.com/tendermint/tm-db" ) // frame stores all Iterators for one contract diff --git a/go-cosmwasm/api/lib.go b/go-cosmwasm/api/lib.go index 41006acad..5beea91a9 100644 --- a/go-cosmwasm/api/lib.go +++ b/go-cosmwasm/api/lib.go @@ -19,13 +19,16 @@ import ( // nice aliases to the rust names type i32 = C.int32_t -type i64 = C.int64_t -type u64 = C.uint64_t -type u32 = C.uint32_t -type u8 = C.uint8_t -type u8_ptr = *C.uint8_t -type usize = C.uintptr_t -type cint = C.int + +type ( + i64 = C.int64_t + u64 = C.uint64_t + u32 = C.uint32_t + u8 = C.uint8_t + u8_ptr = *C.uint8_t + usize = C.uintptr_t + cint = C.int +) type Cache struct { ptr *C.cache_t @@ -267,7 +270,6 @@ func AnalyzeCode( defer runtime.KeepAlive(codeHash) errMsg := C.Buffer{} report, err := C.analyze_code(cache.ptr, cs, &errMsg) - if err != nil { return nil, errorWithMessage(err, errMsg) } diff --git a/go-cosmwasm/api/lib_mock.go b/go-cosmwasm/api/lib_mock.go index 94d304040..77facfb9b 100644 --- a/go-cosmwasm/api/lib_mock.go +++ b/go-cosmwasm/api/lib_mock.go @@ -77,7 +77,7 @@ func InitCache(dataDir string, supportedFeatures string, cacheSize uint64) (Cach } func ReleaseCache(cache Cache) { - //C.release_cache(cache.ptr) + // C.release_cache(cache.ptr) } func InitEnclaveRuntime(ModuleCacheSize uint8) error { diff --git a/go-cosmwasm/api/link_muslc.go b/go-cosmwasm/api/link_muslc.go index f3b7ed4ac..b829c62d1 100644 --- a/go-cosmwasm/api/link_muslc.go +++ b/go-cosmwasm/api/link_muslc.go @@ -1,3 +1,4 @@ +//go:build linux && muslc // +build linux,muslc package api diff --git a/go-cosmwasm/api/link_std.go b/go-cosmwasm/api/link_std.go index b5bd2e4d8..703122fb1 100644 --- a/go-cosmwasm/api/link_std.go +++ b/go-cosmwasm/api/link_std.go @@ -1,3 +1,4 @@ +//go:build !secretcli && linux && !muslc && !darwin // +build !secretcli,linux,!muslc,!darwin package api diff --git a/go-cosmwasm/api/memory.go b/go-cosmwasm/api/memory.go index 94859c445..5e8afe8be 100644 --- a/go-cosmwasm/api/memory.go +++ b/go-cosmwasm/api/memory.go @@ -1,3 +1,4 @@ +//go:build !secretcli // +build !secretcli package api @@ -63,7 +64,7 @@ func receiveVector(b C.Buffer) []byte { // Copy the contents of a vector that was allocated on the Rust side. // Unlike receiveVector, we do not free it, because it will be manually // freed on the Rust side after control returns to it. -//This should be used in places like callbacks from Rust to Go. +// This should be used in places like callbacks from Rust to Go. func receiveSlice(b C.Buffer) []byte { if bufIsNil(b) { return nil diff --git a/go-cosmwasm/cmd/main.go b/go-cosmwasm/cmd/main.go index 1b1856dc8..149d3ccf4 100644 --- a/go-cosmwasm/cmd/main.go +++ b/go-cosmwasm/cmd/main.go @@ -18,9 +18,8 @@ func main() { } fmt.Println("Loaded!") - os.MkdirAll("tmp", 0755) + os.MkdirAll("tmp", 0o755) wasmer, err := wasm.NewWasmer("tmp", "staking", 0, 15) - if err != nil { panic(err) } diff --git a/go-cosmwasm/types/queries.go b/go-cosmwasm/types/queries.go index 913cc6cd3..90519e2a4 100644 --- a/go-cosmwasm/types/queries.go +++ b/go-cosmwasm/types/queries.go @@ -247,8 +247,10 @@ type MintQuery struct { BondedRatio *MintingBondedRatioQuery `json:"bonded_ratio,omitempty"` } -type MintingBondedRatioQuery struct{} -type MintingInflationQuery struct{} +type ( + MintingBondedRatioQuery struct{} + MintingInflationQuery struct{} +) type MintingInflationResponse struct { InflationRate string `json:"inflation_rate"` @@ -316,7 +318,7 @@ func (d ProposalsResponse) MarshalJSON() ([]byte, error) { if len(d.Proposals) == 0 { return []byte("{\"proposals\": []}"), nil } - var raw = d.Proposals + raw := d.Proposals asBytes, err := json.Marshal(raw) if err != nil { return nil, err diff --git a/go-cosmwasm/types/queries_test.go b/go-cosmwasm/types/queries_test.go index 861b507e3..ebaca168f 100644 --- a/go-cosmwasm/types/queries_test.go +++ b/go-cosmwasm/types/queries_test.go @@ -2,9 +2,10 @@ package types import ( "encoding/json" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestDelegationWithEmptyArray(t *testing.T) { diff --git a/go-cosmwasm/types/systemerror.go b/go-cosmwasm/types/systemerror.go index bdfd6639e..064c9ae18 100644 --- a/go-cosmwasm/types/systemerror.go +++ b/go-cosmwasm/types/systemerror.go @@ -7,12 +7,12 @@ import ( // SystemError captures all errors returned from the Rust code as SystemError. // Exactly one of the fields should be set. type SystemError struct { - InvalidRequest *InvalidRequest `json:"invalid_request,omitempty"` - InvalidResponse *InvalidResponse `json:"invalid_response,omitempty"` - NoSuchContract *NoSuchContract `json:"no_such_contract,omitempty"` - Unknown *Unknown `json:"unknown,omitempty"` - UnsupportedRequest *UnsupportedRequest `json:"unsupported_request,omitempty"` - ExceededRecursionLimit *ExceededRecursionLimit `json:"exceeded_recursion_limit,omitempty"` + InvalidRequest *InvalidRequest `json:"invalid_request,omitempty"` + InvalidResponse *InvalidResponse `json:"invalid_response,omitempty"` + NoSuchContract *NoSuchContract `json:"no_such_contract,omitempty"` + Unknown *Unknown `json:"unknown,omitempty"` + UnsupportedRequest *UnsupportedRequest `json:"unsupported_request,omitempty"` + ExceededRecursionLimit *ExceededRecursionLimit `json:"exceeded_recursion_limit,omitempty"` } var ( diff --git a/types/util/prefix.go b/types/util/prefix.go index 06b08fdd7..61129d056 100644 --- a/types/util/prefix.go +++ b/types/util/prefix.go @@ -19,13 +19,11 @@ const ( CoinPurpose = 44 ) -var ( - // AddressVerifier secret address verifier - AddressVerifier = func(bz []byte) error { - if n := len(bz); n != 20 { - return fmt.Errorf("incorrect address length %d", n) - } - - return nil +// AddressVerifier secret address verifier +var AddressVerifier = func(bz []byte) error { + if n := len(bz); n != 20 { + return fmt.Errorf("incorrect address length %d", n) } -) + + return nil +} diff --git a/x/compute/client/cli/query.go b/x/compute/client/cli/query.go index 7f29ad06e..a718cd027 100644 --- a/x/compute/client/cli/query.go +++ b/x/compute/client/cli/query.go @@ -7,14 +7,13 @@ import ( "encoding/json" "errors" "fmt" + "io/ioutil" + "strconv" "github.com/gogo/protobuf/proto" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" - "io/ioutil" - "strconv" - sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" cosmwasmTypes "github.com/enigmampc/SecretNetwork/go-cosmwasm/types" flag "github.com/spf13/pflag" @@ -219,7 +218,7 @@ func GetCmdQueryCode() *cobra.Command { } fmt.Printf("Downloading wasm code to %s\n", args[1]) - return ioutil.WriteFile(args[1], code.Data, 0644) + return ioutil.WriteFile(args[1], code.Data, 0o644) }, } @@ -558,7 +557,6 @@ func QueryWithData(contractAddress sdk.AccAddress, queryData []byte, cliCtx clie nonce := queryData[:32] res, _, err := cliCtx.QueryWithData(route, queryData) - if err != nil { if types.ErrContainsQueryError(err) { errorPlainBz, err := wasmCtx.DecryptError(err.Error(), "query", nonce) diff --git a/x/compute/client/cli/tx.go b/x/compute/client/cli/tx.go index e502ae839..606cc6c07 100644 --- a/x/compute/client/cli/tx.go +++ b/x/compute/client/cli/tx.go @@ -48,9 +48,9 @@ func GetTxCmd() *cobra.Command { InstantiateContractCmd(), ExecuteContractCmd(), // Currently not supporting these commands - //MigrateContractCmd(cdc), - //UpdateContractAdminCmd(cdc), - //ClearContractAdminCmd(cdc), + // MigrateContractCmd(cdc), + // UpdateContractAdminCmd(cdc), + // ClearContractAdminCmd(cdc), ) return txCmd } diff --git a/x/compute/client/rest/tx.go b/x/compute/client/rest/tx.go index 33fc9479e..d630e09c9 100644 --- a/x/compute/client/rest/tx.go +++ b/x/compute/client/rest/tx.go @@ -1,11 +1,12 @@ package rest import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" "net/http" "strconv" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/gorilla/mux" diff --git a/x/compute/client/utils/utils.go b/x/compute/client/utils/utils.go index dd865b417..a64041bfc 100644 --- a/x/compute/client/utils/utils.go +++ b/x/compute/client/utils/utils.go @@ -98,7 +98,7 @@ func (ctx WASMContext) GetTxSenderKeyPair() (privkey []byte, pubkey []byte, er e return nil, nil, err } - err = ioutil.WriteFile(keyPairFilePath, keyPairJSONBytes, 0644) + err = ioutil.WriteFile(keyPairFilePath, keyPairJSONBytes, 0o644) if err != nil { return nil, nil, err } diff --git a/x/compute/client/utils/utils_test.go b/x/compute/client/utils/utils_test.go index 0594a9a96..86f7ce67b 100644 --- a/x/compute/client/utils/utils_test.go +++ b/x/compute/client/utils/utils_test.go @@ -1,14 +1,14 @@ package utils import ( - "github.com/stretchr/testify/require" "io/ioutil" "testing" + + "github.com/stretchr/testify/require" ) func GetTestData() ([]byte, []byte, []byte, error) { wasmCode, err := ioutil.ReadFile("../../internal/keeper/testdata/contract.wasm") - if err != nil { return nil, nil, nil, err } @@ -46,8 +46,10 @@ func TestIsGzip(t *testing.T) { func TestGzipIt(t *testing.T) { wasmCode, someRandomStr, _, err := GetTestData() - originalGzipData := []byte{31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 202, 72, 205, 201, 201, 87, 40, 207, 47, 202, 73, 1, - 4, 0, 0, 255, 255, 133, 17, 74, 13, 11, 0, 0, 0} + originalGzipData := []byte{ + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 202, 72, 205, 201, 201, 87, 40, 207, 47, 202, 73, 1, + 4, 0, 0, 255, 255, 133, 17, 74, 13, 11, 0, 0, 0, + } require.NoError(t, err) diff --git a/x/compute/handler.go b/x/compute/handler.go index 5cd26b42e..71e56c7d4 100644 --- a/x/compute/handler.go +++ b/x/compute/handler.go @@ -122,7 +122,6 @@ func handleExecute(ctx sdk.Context, k Keeper, msg *MsgExecuteContract) (*sdk.Res msg.SentFunds, msg.CallbackSig, ) - if err != nil { return res, err } diff --git a/x/compute/internal/keeper/genesis.go b/x/compute/internal/keeper/genesis.go index f69866168..5be357ee6 100644 --- a/x/compute/internal/keeper/genesis.go +++ b/x/compute/internal/keeper/genesis.go @@ -46,7 +46,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) error if keeper.peekAutoIncrementID(ctx, types.KeyLastInstanceID) <= uint64(maxContractID) { return sdkerrors.Wrapf(types.ErrInvalid, "seq %s must be greater %d ", string(types.KeyLastInstanceID), maxContractID) } - //keeper.setParams(ctx, data.Params) + // keeper.setParams(ctx, data.Params) return nil } @@ -55,7 +55,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) error func ExportGenesis(ctx sdk.Context, keeper Keeper) *types.GenesisState { var genState types.GenesisState - //genState.Params = keeper.GetParams(ctx) + // genState.Params = keeper.GetParams(ctx) keeper.IterateCodeInfos(ctx, func(codeID uint64, info types.CodeInfo) bool { bytecode, err := keeper.GetByteCode(ctx, codeID) diff --git a/x/compute/internal/keeper/gov_test.go b/x/compute/internal/keeper/gov_test.go index 23e0509f6..dd3d72915 100644 --- a/x/compute/internal/keeper/gov_test.go +++ b/x/compute/internal/keeper/gov_test.go @@ -15,9 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) -var ( - TestProposal = types.NewTextProposal("Test", "description") -) +var TestProposal = types.NewTextProposal("Test", "description") type GovInitMsg struct{} diff --git a/x/compute/internal/keeper/handler_plugin.go b/x/compute/internal/keeper/handler_plugin.go index 59331beb8..f557fcffc 100644 --- a/x/compute/internal/keeper/handler_plugin.go +++ b/x/compute/internal/keeper/handler_plugin.go @@ -72,7 +72,8 @@ func NewMessageHandler( channelKeeper channelkeeper.Keeper, capabilityKeeper capabilitykeeper.ScopedKeeper, portSource types.ICS20TransferPortSource, - unpacker codectypes.AnyUnpacker) Messenger { + unpacker codectypes.AnyUnpacker, +) Messenger { encoders := DefaultEncoders(portSource, unpacker).Merge(customEncoders) return NewMessageHandlerChain( NewSDKMessageHandler(router, encoders), @@ -140,14 +141,16 @@ func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, cont return nil, nil, h.channelKeeper.SendPacket(ctx, channelCap, packet) } -type BankEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.BankMsg) ([]sdk.Msg, error) -type CustomEncoder func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) -type DistributionEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.DistributionMsg) ([]sdk.Msg, error) -type GovEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.GovMsg) ([]sdk.Msg, error) -type IBCEncoder func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *v1wasmTypes.IBCMsg) ([]sdk.Msg, error) -type StakingEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.StakingMsg) ([]sdk.Msg, error) -type StargateEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.StargateMsg) ([]sdk.Msg, error) -type WasmEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.WasmMsg) ([]sdk.Msg, error) +type ( + BankEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.BankMsg) ([]sdk.Msg, error) + CustomEncoder func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) + DistributionEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.DistributionMsg) ([]sdk.Msg, error) + GovEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.GovMsg) ([]sdk.Msg, error) + IBCEncoder func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *v1wasmTypes.IBCMsg) ([]sdk.Msg, error) + StakingEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.StakingMsg) ([]sdk.Msg, error) + StargateEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.StargateMsg) ([]sdk.Msg, error) + WasmEncoder func(sender sdk.AccAddress, msg *v1wasmTypes.WasmMsg) ([]sdk.Msg, error) +) type MessageEncoders struct { Bank BankEncoder @@ -524,7 +527,6 @@ func (h MessageHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress ) for _, sdkMsg := range sdkMsgs { sdkEvents, sdkData, err := h.handleSdkMessage(ctx, contractAddr, sdkMsg) - if err != nil { data = append(data, sdkData) return nil, data, err @@ -536,7 +538,7 @@ func (h MessageHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress return events, data, nil - //return nil, nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown variant of CosmosMsgVersion") + // return nil, nil, sdkerrors.Wrap(types.ErrInvalidMsg, "Unknown variant of CosmosMsgVersion") } func (h MessageHandler) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Address, msg sdk.Msg) (sdk.Events, []byte, error) { diff --git a/x/compute/internal/keeper/handler_plugin_test.go b/x/compute/internal/keeper/handler_plugin_test.go index 38f4f81d1..7c7dc4eb7 100644 --- a/x/compute/internal/keeper/handler_plugin_test.go +++ b/x/compute/internal/keeper/handler_plugin_test.go @@ -282,5 +282,4 @@ func TestEncoding(t *testing.T) { } }) } - } diff --git a/x/compute/internal/keeper/ioutil.go b/x/compute/internal/keeper/ioutil.go index 640545e1c..e7906d1cc 100644 --- a/x/compute/internal/keeper/ioutil.go +++ b/x/compute/internal/keeper/ioutil.go @@ -3,9 +3,10 @@ package keeper import ( "bytes" "compress/gzip" - "github.com/enigmampc/SecretNetwork/x/compute/internal/types" "io" "io/ioutil" + + "github.com/enigmampc/SecretNetwork/x/compute/internal/types" ) // magic bytes to identify gzip. diff --git a/x/compute/internal/keeper/ioutil_test.go b/x/compute/internal/keeper/ioutil_test.go index a6d3c7ff4..8944cae5b 100644 --- a/x/compute/internal/keeper/ioutil_test.go +++ b/x/compute/internal/keeper/ioutil_test.go @@ -77,7 +77,6 @@ func TestUncompress(t *testing.T) { require.Equal(t, spec.expResult, r) }) } - } func asGzip(src string) []byte { diff --git a/x/compute/internal/keeper/keeper.go b/x/compute/internal/keeper/keeper.go index ce990e4fe..72dc060d2 100644 --- a/x/compute/internal/keeper/keeper.go +++ b/x/compute/internal/keeper/keeper.go @@ -74,7 +74,7 @@ type Keeper struct { queryGasLimit uint64 serviceRouter MsgServiceRouter // authZPolicy AuthorizationPolicy - //paramSpace subspace.Subspace + // paramSpace subspace.Subspace } // MsgServiceRouter expected MsgServiceRouter interface @@ -332,7 +332,6 @@ func V010MsgToV1SubMsg(contractAddress string, msg v010wasmTypes.CosmosMsg) (v1w Instantiate: msg.Wasm.Instantiate, }, } - } else if msg.Gov != nil { subMsg.Msg = v1wasmTypes.CosmosMsg{ Gov: &v1wasmTypes.GovMsg{ @@ -734,7 +733,6 @@ func (k Keeper) GetContractAddress(ctx sdk.Context, label string) sdk.AccAddress } func (k Keeper) GetContractHash(ctx sdk.Context, contractAddress sdk.AccAddress) []byte { - codeId := k.GetContractInfo(ctx, contractAddress).CodeID hash := k.GetCodeInfo(ctx, codeId).CodeHash @@ -766,13 +764,12 @@ func (k Keeper) setContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress, func (k Keeper) setContractCustomInfo(ctx sdk.Context, contractAddress sdk.AccAddress, contract *types.ContractCustomInfo) { store := ctx.KVStore(k.storeKey) store.Set(types.GetContractEnclaveKey(contractAddress), contract.EnclaveKey) - //println(fmt.Sprintf("Setting enclave key: %x: %x\n", types.GetContractEnclaveKey(contractAddress), contract.EnclaveKey)) + // println(fmt.Sprintf("Setting enclave key: %x: %x\n", types.GetContractEnclaveKey(contractAddress), contract.EnclaveKey)) store.Set(types.GetContractLabelPrefix(contract.Label), contractAddress) - //println(fmt.Sprintf("Setting label: %x: %x\n", types.GetContractLabelPrefix(contract.Label), contractAddress)) + // println(fmt.Sprintf("Setting label: %x: %x\n", types.GetContractLabelPrefix(contract.Label), contractAddress)) } func (k Keeper) IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.ContractInfo, types.ContractCustomInfo) bool) { - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractKeyPrefix) iter := prefixStore.Iterator(nil, nil) for ; iter.Valid(); iter.Next() { @@ -780,8 +777,8 @@ func (k Keeper) IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, typ k.cdc.MustUnmarshal(iter.Value(), &contract) enclaveId := ctx.KVStore(k.storeKey).Get(types.GetContractEnclaveKey(iter.Key())) - //println(fmt.Sprintf("Setting enclave key: %x: %x\n", types.GetContractEnclaveKey(iter.Key()), enclaveId)) - //println(fmt.Sprintf("Setting label: %x: %x\n", types.GetContractLabelPrefix(contract.Label), contract.Label)) + // println(fmt.Sprintf("Setting enclave key: %x: %x\n", types.GetContractEnclaveKey(iter.Key()), enclaveId)) + // println(fmt.Sprintf("Setting label: %x: %x\n", types.GetContractLabelPrefix(contract.Label), contract.Label)) contractCustomInfo := types.ContractCustomInfo{ EnclaveKey: enclaveId, @@ -942,7 +939,6 @@ func contractAddress(codeID, instanceID uint64) sdk.AccAddress { // overflow 32 bits. This is highly improbable, but something that could be refactored. contractID := codeID<<32 + instanceID return addrFromUint64(contractID) - } func (k Keeper) GetNextCodeID(ctx sdk.Context) uint64 { @@ -1078,7 +1074,7 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply v1w // instantiate wasm contract gas := gasForContract(ctx) marshaledReply, error := json.Marshal(reply) - //marshaledReply = append(replyToContractHash, marshaledReply...) + // marshaledReply = append(replyToContractHash, marshaledReply...) marshaledReply = append(ogTx[0:64], marshaledReply...) if error != nil { @@ -1110,5 +1106,4 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply v1w default: return nil, sdkerrors.Wrap(types.ErrReplyFailed, fmt.Sprintf("cannot detect response type: %+v", res)) } - } diff --git a/x/compute/internal/keeper/keeper_test.go b/x/compute/internal/keeper/keeper_test.go index d87a78a87..2c20e1df8 100644 --- a/x/compute/internal/keeper/keeper_test.go +++ b/x/compute/internal/keeper/keeper_test.go @@ -279,7 +279,7 @@ func TestIsSimulationMode(t *testing.T) { } for msg := range specs { t.Run(msg, func(t *testing.T) { - //require.Equal(t, spec.exp, isSimulationMode(spec.ctx)) + // require.Equal(t, spec.exp, isSimulationMode(spec.ctx)) }) } } @@ -596,7 +596,7 @@ func TestExecute(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) key := keeper.GetCodeInfo(ctx, contractID).CodeHash - //keyStr := hex.EncodeToString(key) + // keyStr := hex.EncodeToString(key) msg := types.SecretMsg{ CodeHash: []byte(hex.EncodeToString(key)), @@ -647,12 +647,12 @@ func TestExecute(t *testing.T) { gasBefore = ctx.GasMeter().GasConsumed() require.NoError(t, err) - //res, _, _, err := execHelper(t, keeper, trialCtx, addr, creator, `{"release":{}}`, true, false, defaultGasForTests) + // res, _, _, err := execHelper(t, keeper, trialCtx, addr, creator, `{"release":{}}`, true, false, defaultGasForTests) initMsgBz = []byte(`{"release":{}}`) key = keeper.GetCodeInfo(ctx, contractID).CodeHash - //keyStr := hex.EncodeToString(key) + // keyStr := hex.EncodeToString(key) msg = types.SecretMsg{ CodeHash: []byte(hex.EncodeToString(key)), diff --git a/x/compute/internal/keeper/legacy_querier.go b/x/compute/internal/keeper/legacy_querier.go index 5269b8af7..949c7e9c1 100644 --- a/x/compute/internal/keeper/legacy_querier.go +++ b/x/compute/internal/keeper/legacy_querier.go @@ -21,7 +21,7 @@ const ( QueryContractAddress = "label" QueryContractKey = "contract-key" QueryContractHash = "contract-hash" - //QueryContractHistory = "contract-history" + // QueryContractHistory = "contract-history" ) const QueryMethodContractStateSmart = "smart" @@ -106,7 +106,7 @@ func NewLegacyQuerier(keeper Keeper) sdk.Querier { return nil, nil } - //bz, err = keeper.legacyAmino.MarshalJSON(rsp) + // bz, err = keeper.legacyAmino.MarshalJSON(rsp) bz, err = json.MarshalIndent(rsp, "", " ") if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) @@ -159,5 +159,4 @@ func queryContractState(ctx sdk.Context, bech, queryMethod string, data []byte, } return bz, nil */ - } diff --git a/x/compute/internal/keeper/param_verification_test.go b/x/compute/internal/keeper/param_verification_test.go index 8a3f60988..aa2c20e48 100644 --- a/x/compute/internal/keeper/param_verification_test.go +++ b/x/compute/internal/keeper/param_verification_test.go @@ -78,6 +78,7 @@ func multisigTxCreator( signModeHandler := multisigTxCreatorForExisting(t, ctx, multisigAccount, signers, actualSigners, sdkMsg) return signModeHandler, signers, multisigAccount } + func multisigTxCreatorForExisting( t *testing.T, ctx *sdk.Context, multisigAccount Account, signers []Account, actualSigners int, sdkMsg sdk.Msg, ) authsigning.SignModeHandler { @@ -803,7 +804,7 @@ func TestInvalidKeyType(t *testing.T) { initMsgBz, err := wasmCtx.Encrypt(msg.Serialize()) require.NoError(t, err) - //nonce := initMsgBz[0:32] + // nonce := initMsgBz[0:32] sdkMsg := types.MsgInstantiateContract{ Sender: edAddr, diff --git a/x/compute/internal/keeper/querier.go b/x/compute/internal/keeper/querier.go index 494330fa5..5a30da3cf 100644 --- a/x/compute/internal/keeper/querier.go +++ b/x/compute/internal/keeper/querier.go @@ -118,7 +118,6 @@ func (q GrpcQuerier) SmartContractState(c context.Context, req *types.QuerySmart return nil, types.ErrNotFound } return &types.QuerySmartContractStateResponse{Data: rsp}, nil - } func (q GrpcQuerier) Code(c context.Context, req *types.QueryCodeRequest) (*types.QueryCodeResponse, error) { @@ -159,7 +158,6 @@ func (q GrpcQuerier) AddressByLabel(c context.Context, req *types.QueryContractA return nil, types.ErrNotFound } return &types.QueryContractAddressByLabelResponse{Address: rsp}, nil - } func (q GrpcQuerier) ContractKey(c context.Context, req *types.QueryContractKeyRequest) (*types.QueryContractKeyResponse, error) { @@ -175,7 +173,6 @@ func (q GrpcQuerier) ContractKey(c context.Context, req *types.QueryContractKeyR return nil, types.ErrNotFound } return &types.QueryContractKeyResponse{Key: rsp}, nil - } func (q GrpcQuerier) ContractHash(c context.Context, req *types.QueryContractHashRequest) (*types.QueryContractHashResponse, error) { @@ -191,7 +188,6 @@ func (q GrpcQuerier) ContractHash(c context.Context, req *types.QueryContractHas return nil, types.ErrNotFound } return &types.QueryContractHashResponse{CodeHash: rsp}, nil - } func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper Keeper) (*types.ContractInfoWithAddress, error) { diff --git a/x/compute/internal/keeper/querier_test.go b/x/compute/internal/keeper/querier_test.go index f0f4f2c34..e92d834a3 100644 --- a/x/compute/internal/keeper/querier_test.go +++ b/x/compute/internal/keeper/querier_test.go @@ -92,7 +92,7 @@ func TestQueryContractLabel(t *testing.T) { for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - //binResult, err := q(ctx, spec.srcPath, spec.srcReq) + // binResult, err := q(ctx, spec.srcPath, spec.srcReq) binResult, err := q(ctx, spec.srcPath, spec.srcReq) // require.True(t, spec.expErr.Is(err), "unexpected error") require.True(t, spec.expErr.Is(err), err) diff --git a/x/compute/internal/keeper/query_plugins.go b/x/compute/internal/keeper/query_plugins.go index fcd934322..66d201222 100644 --- a/x/compute/internal/keeper/query_plugins.go +++ b/x/compute/internal/keeper/query_plugins.go @@ -2,9 +2,10 @@ package keeper import ( "encoding/json" - "github.com/enigmampc/SecretNetwork/x/compute/internal/types" "strings" + "github.com/enigmampc/SecretNetwork/x/compute/internal/types" + "github.com/cosmos/cosmos-sdk/codec" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" @@ -171,7 +172,6 @@ func MintQuerier(keeper mintkeeper.Keeper) func(ctx sdk.Context, request *wasmTy } return nil, wasmTypes.UnsupportedRequest{Kind: "unknown MintQuery variant"} } - } func DistQuerier(keeper distrkeeper.Keeper) func(ctx sdk.Context, request *wasmTypes.DistQuery) ([]byte, error) { @@ -278,7 +278,7 @@ func StakingQuerier(keeper stakingkeeper.Keeper, distKeeper distrkeeper.Keeper) } if request.Validators != nil { validators := keeper.GetBondedValidatorsByPower(ctx) - //validators := keeper.GetAllValidators(ctx) + // validators := keeper.GetAllValidators(ctx) wasmVals := make([]wasmTypes.Validator, len(validators)) for i, v := range validators { wasmVals[i] = wasmTypes.Validator{ @@ -360,7 +360,6 @@ func sdkToUnbondingDelegations(bondDenom string, delegations stakingtypes.Unbond result := make([]wasmTypes.Delegation, len(delegations)) for i, d := range delegations { - for _, e := range d.Entries { wasmCoin := wasmTypes.Coin{ @@ -375,7 +374,6 @@ func sdkToUnbondingDelegations(bondDenom string, delegations stakingtypes.Unbond } } - } return result, nil } diff --git a/x/compute/internal/keeper/secret_contracts_test.go b/x/compute/internal/keeper/secret_contracts_test.go index 6042056f4..dbe2f0634 100644 --- a/x/compute/internal/keeper/secret_contracts_test.go +++ b/x/compute/internal/keeper/secret_contracts_test.go @@ -1573,6 +1573,7 @@ func TestExternalQueryCalleePanic(t *testing.T) { }) } } + func TestExternalQueryCalleeStdError(t *testing.T) { for _, testContract := range testContracts { t.Run(testContract.CosmWasmVersion, func(t *testing.T) { @@ -1624,7 +1625,6 @@ func TestExternalQueryBadSenderABI(t *testing.T) { require.Equal(t, "test_contract::contract::QueryMsg", err.ParseErr.Target) require.Equal(t, "Invalid type", err.ParseErr.Msg) } - }) } } diff --git a/x/compute/internal/keeper/test_common.go b/x/compute/internal/keeper/test_common.go index cb9639ac0..c4269232b 100644 --- a/x/compute/internal/keeper/test_common.go +++ b/x/compute/internal/keeper/test_common.go @@ -93,8 +93,10 @@ import ( "github.com/enigmampc/SecretNetwork/x/registration" ) -const flagLRUCacheSize = "lru_size" -const flagQueryGasLimit = "query_gas_limit" +const ( + flagLRUCacheSize = "lru_size" + flagQueryGasLimit = "query_gas_limit" +) var _ wasmtypes.ICS20TransferPortSource = &MockIBCTransferKeeper{} @@ -122,16 +124,17 @@ var ModuleBasics = module.NewBasicManager( params.AppModuleBasic{}, crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, - //ibc.AppModuleBasic{}, + // ibc.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, - //transfer.AppModuleBasic{}, + // transfer.AppModuleBasic{}, registration.AppModuleBasic{}, ) func MakeTestCodec() codec.Codec { return MakeEncodingConfig().Marshaler } + func MakeEncodingConfig() simappparams.EncodingConfig { amino := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() @@ -257,14 +260,14 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc blockedAddrs, ) - //bankParams = bankParams.SetSendEnabledParam(sdk.DefaultBondDenom, true) + // bankParams = bankParams.SetSendEnabledParam(sdk.DefaultBondDenom, true) bankKeeper.SetParams(ctx, banktypes.DefaultParams()) stakingSubsp, _ := paramsKeeper.GetSubspace(stakingtypes.ModuleName) stakingKeeper := stakingkeeper.NewKeeper(encodingConfig.Marshaler, keyStaking, authKeeper, bankKeeper, stakingSubsp) stakingKeeper.SetParams(ctx, TestingStakeParams) - //mintSubsp, _ := paramsKeeper.GetSubspace(minttypes.ModuleName) + // mintSubsp, _ := paramsKeeper.GetSubspace(minttypes.ModuleName) //mintKeeper := mintkeeper.NewKeeper(encodingConfig.Marshaler, // keyBank, @@ -303,8 +306,8 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc err = bankKeeper.MintCoins(ctx, faucetAccountName, totalSupply) require.NoError(t, err) - //err = bankKeeper.SendCoinsFromModuleToAccount(ctx, faucetAccountName, distrAcc.GetAddress(), totalSupply) - //require.NoError(t, err) + // err = bankKeeper.SendCoinsFromModuleToAccount(ctx, faucetAccountName, distrAcc.GetAddress(), totalSupply) + // require.NoError(t, err) notBondedPool := authtypes.NewEmptyModuleAccount(stakingtypes.NotBondedPoolName, authtypes.Burner, authtypes.Staking) bondPool := authtypes.NewEmptyModuleAccount(stakingtypes.BondedPoolName, authtypes.Burner, authtypes.Staking) @@ -330,14 +333,14 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(paramsKeeper)). AddRoute(distrtypes.RouterKey, distribution.NewCommunityPoolSpendProposalHandler(distKeeper)) - //AddRoute(wasmtypes.RouterKey, NewWasmProposalHandler(keeper, wasmtypes.EnableAllProposals)) + // AddRoute(wasmtypes.RouterKey, NewWasmProposalHandler(keeper, wasmtypes.EnableAllProposals)) govKeeper := govkeeper.NewKeeper( encodingConfig.Marshaler, keyGov, paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()), authKeeper, bankKeeper, stakingKeeper, govRouter, ) // bank := bankKeeper. - //bk := bank.Keeper(bankKeeper) + // bk := bank.Keeper(bankKeeper) mintSubsp, _ := paramsKeeper.GetSubspace(minttypes.ModuleName) mintKeeper := mintkeeper.NewKeeper(encodingConfig.Marshaler, mintStore, mintSubsp, stakingKeeper, authKeeper, bankKeeper, authtypes.FeeCollectorName) @@ -390,17 +393,17 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc ) // todo: new grpc routing - //serviceRouter := baseapp.NewMsgServiceRouter() + // serviceRouter := baseapp.NewMsgServiceRouter() - //serviceRouter.SetInterfaceRegistry(encodingConfig.InterfaceRegistry) - //bankMsgServer := bankkeeper.NewMsgServerImpl(bankKeeper) - //stakingMsgServer := stakingkeeper.NewMsgServerImpl(stakingKeeper) - //distrMsgServer := distrkeeper.NewMsgServerImpl(distKeeper) - //wasmMsgServer := NewMsgServerImpl(keeper) + // serviceRouter.SetInterfaceRegistry(encodingConfig.InterfaceRegistry) + // bankMsgServer := bankkeeper.NewMsgServerImpl(bankKeeper) + // stakingMsgServer := stakingkeeper.NewMsgServerImpl(stakingKeeper) + // distrMsgServer := distrkeeper.NewMsgServerImpl(distKeeper) + // wasmMsgServer := NewMsgServerImpl(keeper) - //banktypes.RegisterMsgServer(serviceRouter, bankMsgServer) - //stakingtypes.RegisterMsgServer(serviceRouter, stakingMsgServer) - //distrtypes.RegisterMsgServer(serviceRouter, distrMsgServer) + // banktypes.RegisterMsgServer(serviceRouter, bankMsgServer) + // stakingtypes.RegisterMsgServer(serviceRouter, stakingMsgServer) + // distrtypes.RegisterMsgServer(serviceRouter, distrMsgServer) keeper := NewKeeper( encodingConfig.Marshaler, @@ -424,7 +427,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc encoders, queriers, ) - //keeper.setParams(ctx, wasmtypes.DefaultParams()) + // keeper.setParams(ctx, wasmtypes.DefaultParams()) // add wasm handler so we can loop-back (contracts calling contracts) router.AddRoute(sdk.NewRoute(wasmtypes.RouterKey, TestHandler(keeper))) diff --git a/x/compute/internal/keeper/test_fuzz.go b/x/compute/internal/keeper/test_fuzz.go index b345f2805..c5d625beb 100644 --- a/x/compute/internal/keeper/test_fuzz.go +++ b/x/compute/internal/keeper/test_fuzz.go @@ -1,8 +1,8 @@ package keeper import ( - "github.com/enigmampc/SecretNetwork/x/compute/internal/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/enigmampc/SecretNetwork/x/compute/internal/types" fuzz "github.com/google/gofuzz" tmBytes "github.com/tendermint/tendermint/libs/bytes" ) diff --git a/x/compute/internal/types/msg_test.go b/x/compute/internal/types/msg_test.go index 35f7db37c..3ab8fa108 100644 --- a/x/compute/internal/types/msg_test.go +++ b/x/compute/internal/types/msg_test.go @@ -31,13 +31,12 @@ func TestBuilderRegexp(t *testing.T) { assert.Error(t, err) } }) - } } func TestStoreCodeValidation(t *testing.T) { badAddress := sdk.AccAddress(make([]byte, 2000)) - //require.NoError(t, err) + // require.NoError(t, err) // proper address size goodAddress := sdk.AccAddress(make([]byte, 20)) @@ -239,7 +238,7 @@ func TestInstantiateContractValidation(t *testing.T) { func TestExecuteContractValidation(t *testing.T) { badAddress := sdk.AccAddress(make([]byte, 2000)) - //require.NoError(t, err) + // require.NoError(t, err) // proper address size goodAddress := sdk.AccAddress(make([]byte, 20)) diff --git a/x/compute/internal/types/types.go b/x/compute/internal/types/types.go index 456c941a9..b36c03854 100644 --- a/x/compute/internal/types/types.go +++ b/x/compute/internal/types/types.go @@ -15,9 +15,11 @@ import ( "github.com/spf13/cast" ) -const defaultLRUCacheSize = uint64(0) -const defaultEnclaveLRUCacheSize = uint8(0) // can safely go up to 15 -const defaultQueryGasLimit = uint64(10_000_000) +const ( + defaultLRUCacheSize = uint64(0) + defaultEnclaveLRUCacheSize = uint8(0) // can safely go up to 15 + defaultQueryGasLimit = uint64(10_000_000) +) // base64 of a 64 byte key type ContractKey string @@ -66,6 +68,7 @@ func NewContractInfo(codeID uint64, creator sdk.AccAddress, label string, create Created: createdAt, } } + func (c *ContractInfo) ValidateBasic() error { if c.CodeID == 0 { return sdkerrors.Wrap(ErrEmpty, "code id") diff --git a/x/mauth/keeper/keeper_test.go b/x/mauth/keeper/keeper_test.go index debda201f..1f57b1ec5 100644 --- a/x/mauth/keeper/keeper_test.go +++ b/x/mauth/keeper/keeper_test.go @@ -2,9 +2,10 @@ package keeper_test import ( "encoding/json" + "testing" + "github.com/cosmos/cosmos-sdk/simapp" "github.com/enigmampc/SecretNetwork/x/compute" - "testing" "github.com/stretchr/testify/suite" "github.com/tendermint/tendermint/crypto" diff --git a/x/mauth/keeper/msg_server_test.go b/x/mauth/keeper/msg_server_test.go index 8de620e90..262ddf14c 100644 --- a/x/mauth/keeper/msg_server_test.go +++ b/x/mauth/keeper/msg_server_test.go @@ -74,7 +74,6 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { suite.Require().Error(err) suite.Require().Nil(res) } - }) } } diff --git a/x/mauth/types/msgs.go b/x/mauth/types/msgs.go index 634c5bce5..1eaaa96b1 100644 --- a/x/mauth/types/msgs.go +++ b/x/mauth/types/msgs.go @@ -75,9 +75,7 @@ func PackTxMsgAny(sdkMsg sdk.Msg) (*codectypes.Any, error) { // UnpackInterfaces implements codectypes.UnpackInterfacesMessage func (msg MsgSubmitTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - var ( - sdkMsg sdk.Msg - ) + var sdkMsg sdk.Msg return unpacker.UnpackAny(msg.Msg, &sdkMsg) } @@ -99,7 +97,6 @@ func (msg MsgSubmitTx) GetSigners() []sdk.AccAddress { // ValidateBasic implements sdk.Msg func (msg MsgSubmitTx) ValidateBasic() error { - if len(msg.Msg.GetValue()) == 0 { return fmt.Errorf("can't execute an empty msg") } diff --git a/x/registration/client/cli/query.go b/x/registration/client/cli/query.go index dd564b1eb..e879ddc49 100644 --- a/x/registration/client/cli/query.go +++ b/x/registration/client/cli/query.go @@ -90,12 +90,12 @@ func GetCmdMasterParams() *cobra.Command { return err } - err = ioutil.WriteFile(types.IoExchMasterCertPath, certs.IoMasterCertificate.Bytes, 0644) + err = ioutil.WriteFile(types.IoExchMasterCertPath, certs.IoMasterCertificate.Bytes, 0o644) if err != nil { return err } - err = ioutil.WriteFile(types.NodeExchMasterCertPath, certs.NodeExchMasterCertificate.Bytes, 0644) + err = ioutil.WriteFile(types.NodeExchMasterCertPath, certs.NodeExchMasterCertificate.Bytes, 0o644) if err != nil { return err } diff --git a/x/registration/client/cli/tx.go b/x/registration/client/cli/tx.go index e381b850c..5dc855267 100644 --- a/x/registration/client/cli/tx.go +++ b/x/registration/client/cli/tx.go @@ -1,12 +1,13 @@ package cli import ( + "io/ioutil" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" "github.com/spf13/cobra" - "io/ioutil" ) // GetTxCmd returns the transaction commands for this module @@ -31,7 +32,7 @@ func AuthenticateNodeCmd() *cobra.Command { Short: "Upload a certificate to authenticate the node", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - //clientCtx := client.GetClientContextFromCmd(cmd) + // clientCtx := client.GetClientContextFromCmd(cmd) clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err diff --git a/x/registration/client/rest/query.go b/x/registration/client/rest/query.go index d0c71ba1e..941a21bab 100644 --- a/x/registration/client/rest/query.go +++ b/x/registration/client/rest/query.go @@ -5,10 +5,11 @@ import ( "encoding/hex" "encoding/json" "fmt" + "net/http" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/types/rest" ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation" - "net/http" "github.com/enigmampc/SecretNetwork/x/registration/internal/keeper" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" @@ -168,7 +169,6 @@ func newArgDecoder(def func(string) ([]byte, error)) *argumentDecoder { } func (a *argumentDecoder) DecodeString(s string) ([]byte, error) { - switch a.encoding { case "hex": return hex.DecodeString(s) diff --git a/x/registration/client/rest/tx.go b/x/registration/client/rest/tx.go index f377c66e6..91c2abbb4 100644 --- a/x/registration/client/rest/tx.go +++ b/x/registration/client/rest/tx.go @@ -6,9 +6,9 @@ import ( ) func registerTxRoutes(cliCtx client.Context, r *mux.Router) { - //r.HandleFunc("/wasm/code", storeCodeHandlerFn(cliCtx)).Methods("POST") - //r.HandleFunc("/wasm/code/{codeId}", instantiateContractHandlerFn(cliCtx)).Methods("POST") - //r.HandleFunc("/wasm/contract/{contractAddr}", executeContractHandlerFn(cliCtx)).Methods("POST") + // r.HandleFunc("/wasm/code", storeCodeHandlerFn(cliCtx)).Methods("POST") + // r.HandleFunc("/wasm/code/{codeId}", instantiateContractHandlerFn(cliCtx)).Methods("POST") + // r.HandleFunc("/wasm/contract/{contractAddr}", executeContractHandlerFn(cliCtx)).Methods("POST") } // limit max bytes read to prevent gzip bombs diff --git a/x/registration/handler.go b/x/registration/handler.go index b365f90b7..32a1c3125 100644 --- a/x/registration/handler.go +++ b/x/registration/handler.go @@ -3,6 +3,7 @@ package registration import ( "encoding/hex" "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" diff --git a/x/registration/internal/keeper/genesis.go b/x/registration/internal/keeper/genesis.go index b92de2e08..d3600a20a 100644 --- a/x/registration/internal/keeper/genesis.go +++ b/x/registration/internal/keeper/genesis.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" @@ -10,7 +11,6 @@ import ( // InitGenesis sets supply information for genesis. // func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) { - if data.IoMasterCertificate != nil && data.NodeExchMasterCertificate != nil { // keeper.setMasterPublicKey(ctx, data.MasterPublic) keeper.setMasterCertificate(ctx, *data.IoMasterCertificate, types.MasterIoKeyId) diff --git a/x/registration/internal/keeper/genesis_test.go b/x/registration/internal/keeper/genesis_test.go index 410aba057..99fd4dca9 100644 --- a/x/registration/internal/keeper/genesis_test.go +++ b/x/registration/internal/keeper/genesis_test.go @@ -1,12 +1,13 @@ package keeper import ( - "github.com/enigmampc/SecretNetwork/x/registration/internal/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "io/ioutil" "os" "testing" + + "github.com/enigmampc/SecretNetwork/x/registration/internal/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestInitGenesisNoMaster(t *testing.T) { diff --git a/x/registration/internal/keeper/keeper.go b/x/registration/internal/keeper/keeper.go index 6818ffdbe..3c49c55b1 100644 --- a/x/registration/internal/keeper/keeper.go +++ b/x/registration/internal/keeper/keeper.go @@ -5,13 +5,14 @@ import ( "encoding/hex" "encoding/json" "fmt" + "path/filepath" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation" - "path/filepath" ) // Keeper will have a reference to Wasmer with it's own data directory. @@ -24,7 +25,6 @@ type Keeper struct { // NewKeeper creates a new contract Keeper instance func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, router sdk.Router, enclave EnclaveInterface, homeDir string, bootstrap bool) Keeper { - if !bootstrap { InitializeNode(homeDir, enclave) } @@ -38,7 +38,6 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, router sdk.Router, } func InitializeNode(homeDir string, enclave EnclaveInterface) { - seedPath := filepath.Join(homeDir, types.SecretNodeCfgFolder, types.SecretNodeSeedConfig) if !fileExists(seedPath) { diff --git a/x/registration/internal/keeper/keeper_test.go b/x/registration/internal/keeper/keeper_test.go index 0bbcc0f72..8ed51f22c 100644 --- a/x/registration/internal/keeper/keeper_test.go +++ b/x/registration/internal/keeper/keeper_test.go @@ -1,15 +1,16 @@ package keeper import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + sdk "github.com/cosmos/cosmos-sdk/types" eng "github.com/enigmampc/SecretNetwork/types" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation" "github.com/stretchr/testify/require" - "io/ioutil" - "os" - "path/filepath" - "testing" ) func init() { @@ -35,10 +36,10 @@ func TestNewKeeper_Node(t *testing.T) { seedPath := filepath.Join(tempDir, types.SecretNodeCfgFolder, types.SecretNodeSeedConfig) - err = os.MkdirAll(filepath.Join(tempDir, types.SecretNodeCfgFolder), 0700) + err = os.MkdirAll(filepath.Join(tempDir, types.SecretNodeCfgFolder), 0o700) require.NoError(t, err) - err = ioutil.WriteFile(seedPath, CreateTestSeedConfig(t), 0700) + err = ioutil.WriteFile(seedPath, CreateTestSeedConfig(t), 0o700) require.NoError(t, err) _, regKeeper := CreateTestInput(t, false, tempDir, false) @@ -89,5 +90,4 @@ func TestKeeper_RegisterNode(t *testing.T) { _, err = regKeeper.RegisterNode(ctx, cert) require.NoError(t, err) - } diff --git a/x/registration/internal/keeper/legacy_querier.go b/x/registration/internal/keeper/legacy_querier.go index a759eb065..c9b450eea 100644 --- a/x/registration/internal/keeper/legacy_querier.go +++ b/x/registration/internal/keeper/legacy_querier.go @@ -3,10 +3,11 @@ package keeper import ( "encoding/hex" "encoding/json" + "reflect" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abci "github.com/tendermint/tendermint/abci/types" - "reflect" ) const ( diff --git a/x/registration/internal/keeper/querier.go b/x/registration/internal/keeper/querier.go index b60712707..36ddb4bdb 100644 --- a/x/registration/internal/keeper/querier.go +++ b/x/registration/internal/keeper/querier.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "github.com/golang/protobuf/ptypes/empty" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/registration/internal/keeper/querier_test.go b/x/registration/internal/keeper/querier_test.go index c78ed835f..13034f152 100644 --- a/x/registration/internal/keeper/querier_test.go +++ b/x/registration/internal/keeper/querier_test.go @@ -5,13 +5,14 @@ package keeper import ( "encoding/hex" "encoding/json" - sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/enigmampc/SecretNetwork/x/registration/internal/types" - ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation" "io/ioutil" "os" "testing" + sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/enigmampc/SecretNetwork/x/registration/internal/types" + ra "github.com/enigmampc/SecretNetwork/x/registration/remote_attestation" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" ) diff --git a/x/registration/internal/keeper/registration.go b/x/registration/internal/keeper/registration.go index 681e40f4c..735b0f44b 100644 --- a/x/registration/internal/keeper/registration.go +++ b/x/registration/internal/keeper/registration.go @@ -52,7 +52,7 @@ func (k Keeper) isMasterCertificateDefined(ctx sdk.Context, certType string) boo func (k Keeper) getRegistrationInfo(ctx sdk.Context, publicKey types.NodeID) *types.RegistrationNodeInfo { store := ctx.KVStore(k.storeKey) var nodeInfo types.RegistrationNodeInfo - //fmt.Println("pubkey", hex.EncodeToString(publicKey)) + // fmt.Println("pubkey", hex.EncodeToString(publicKey)) certBz := store.Get(types.RegistrationKeyPrefix(publicKey)) if certBz == nil { @@ -84,8 +84,8 @@ func (k Keeper) SetRegistrationInfo(ctx sdk.Context, certificate types.Registrat return } - //fmt.Println("pubkey", hex.EncodeToString(publicKey)) - //fmt.Println("EncryptedSeed", hex.EncodeToString(certificate.EncryptedSeed)) + // fmt.Println("pubkey", hex.EncodeToString(publicKey)) + // fmt.Println("EncryptedSeed", hex.EncodeToString(certificate.EncryptedSeed)) store.Set(types.RegistrationKeyPrefix(publicKey), k.cdc.MustMarshal(&certificate)) } diff --git a/x/registration/internal/keeper/test_common.go b/x/registration/internal/keeper/test_common.go index c2f17aef4..b773f49e7 100644 --- a/x/registration/internal/keeper/test_common.go +++ b/x/registration/internal/keeper/test_common.go @@ -3,6 +3,9 @@ package keeper import ( "encoding/base64" "encoding/json" + "io/ioutil" + "os" + "testing" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" @@ -20,10 +23,7 @@ import ( "github.com/cosmos/ibc-go/v3/modules/apps/transfer" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - //ibc "github.com/cosmos/cosmos-sdk/x/ibc/core" - "io/ioutil" - "os" - "testing" + // ibc "github.com/cosmos/cosmos-sdk/x/ibc/core" "github.com/cosmos/cosmos-sdk/x/mint" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" @@ -45,7 +45,6 @@ import ( ) func CreateTestSeedConfig(t *testing.T) []byte { - seed := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw") require.NoError(t, err) @@ -73,7 +72,7 @@ var ModuleBasics = module.NewBasicManager( ), crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, - //ibc.AppModuleBasic{}, + // ibc.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, transfer.AppModuleBasic{}, @@ -82,6 +81,7 @@ var ModuleBasics = module.NewBasicManager( func MakeTestCodec() codec.Codec { return MakeEncodingConfig().Marshaler } + func MakeEncodingConfig() params.EncodingConfig { amino := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() @@ -102,7 +102,6 @@ func MakeEncodingConfig() params.EncodingConfig { } func CreateTestInput(t *testing.T, isCheckTx bool, tempDir string, bootstrap bool) (sdk.Context, Keeper) { - err := os.Setenv("SGX_MODE", "SW") require.Nil(t, err) diff --git a/x/registration/internal/types/genesis.go b/x/registration/internal/types/genesis.go index ef05f0157..124a2c7b9 100644 --- a/x/registration/internal/types/genesis.go +++ b/x/registration/internal/types/genesis.go @@ -3,7 +3,6 @@ package types // ValidateGenesis performs basic validation of supply genesis data returning an // error for any failed validation criteria. func ValidateGenesis(data GenesisState) error { - // todo: do we want to use this, or just fail if they don't exist? //if data.IoMasterCertificate == nil { diff --git a/x/registration/internal/types/msg_test.go b/x/registration/internal/types/msg_test.go index faa9ce746..2a5d36610 100644 --- a/x/registration/internal/types/msg_test.go +++ b/x/registration/internal/types/msg_test.go @@ -16,7 +16,7 @@ func TestMsgRaAuthenticateRoute(t *testing.T) { cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw") require.NoError(t, err) // coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10)) - var msg = RaAuthenticate{ + msg := RaAuthenticate{ addr1, cert, } @@ -26,7 +26,6 @@ func TestMsgRaAuthenticateRoute(t *testing.T) { } func TestMsgSendValidation(t *testing.T) { - _ = os.Setenv("SGX_MODE", "SW") addr0 := sdk.AccAddress([]byte("qwlnmxj7prpx8rysxm2u")) @@ -44,10 +43,11 @@ func TestMsgSendValidation(t *testing.T) { cases := []struct { valid bool tx RaAuthenticate - }{{true, RaAuthenticate{ - addr0, - cert, - }}, + }{ + {true, RaAuthenticate{ + addr0, + cert, + }}, // invalid address send {false, RaAuthenticate{ addr0, @@ -75,7 +75,7 @@ func TestMsgSendGetSignBytes(t *testing.T) { cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw") require.NoError(t, err) - var msg = RaAuthenticate{ + msg := RaAuthenticate{ addr0, cert, } @@ -90,7 +90,7 @@ func TestMsgSendGetSigners(t *testing.T) { cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw") require.NoError(t, err) - var msg = RaAuthenticate{ + msg := RaAuthenticate{ addr0, cert, } diff --git a/x/registration/internal/types/types.go b/x/registration/internal/types/types.go index a4d5ba0a1..924955611 100644 --- a/x/registration/internal/types/types.go +++ b/x/registration/internal/types/types.go @@ -5,16 +5,20 @@ import ( "encoding/hex" ) -const EnclaveRegistrationKey = "new_node_seed_exchange_keypair.sealed" -const PublicKeyLength = 64 // encoded length -const EncryptedKeyLength = 96 // encoded length -const MasterNodeKeyId = "NodeExchMasterKey" -const MasterIoKeyId = "IoExchMasterKey" -const SecretNodeSeedConfig = "seed.json" -const SecretNodeCfgFolder = ".node" +const ( + EnclaveRegistrationKey = "new_node_seed_exchange_keypair.sealed" + PublicKeyLength = 64 // encoded length + EncryptedKeyLength = 96 // encoded length + MasterNodeKeyId = "NodeExchMasterKey" + MasterIoKeyId = "IoExchMasterKey" + SecretNodeSeedConfig = "seed.json" + SecretNodeCfgFolder = ".node" +) -const NodeExchMasterCertPath = "node-master-cert.der" -const IoExchMasterCertPath = "io-master-cert.der" +const ( + NodeExchMasterCertPath = "node-master-cert.der" + IoExchMasterCertPath = "io-master-cert.der" +) const AttestationCertPath = "attestation_cert.der" diff --git a/x/registration/module.go b/x/registration/module.go index d1a5563c3..0e4f2fce9 100644 --- a/x/registration/module.go +++ b/x/registration/module.go @@ -3,13 +3,14 @@ package registration import ( "context" "encoding/json" + "math/rand" + "github.com/cosmos/cosmos-sdk/client" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/enigmampc/SecretNetwork/x/registration/internal/keeper" "github.com/enigmampc/SecretNetwork/x/registration/internal/types" "github.com/grpc-ecosystem/grpc-gateway/runtime" - "math/rand" "github.com/gorilla/mux" "github.com/spf13/cobra" diff --git a/x/registration/remote_attestation/fuzz_test.go b/x/registration/remote_attestation/fuzz_test.go index e974766aa..12d6676ab 100644 --- a/x/registration/remote_attestation/fuzz_test.go +++ b/x/registration/remote_attestation/fuzz_test.go @@ -1,5 +1,6 @@ // rename this to fuzz.go if you want to run the fuzzer +//go:build gofuzz // +build gofuzz package remote_attestation diff --git a/x/registration/remote_attestation/ra_test.go b/x/registration/remote_attestation/ra_test.go index 7985003d1..42c51281e 100644 --- a/x/registration/remote_attestation/ra_test.go +++ b/x/registration/remote_attestation/ra_test.go @@ -1,10 +1,11 @@ package remote_attestation import ( - "github.com/stretchr/testify/require" "io/ioutil" "os" "testing" + + "github.com/stretchr/testify/require" ) func Test_ValidateCertificateHwMode(t *testing.T) { @@ -39,8 +40,7 @@ func Test_InvalidRandomDataAsCert(t *testing.T) { } func Test_FuzzCrashers(t *testing.T) { - - var crashers = [][]byte{ + crashers := [][]byte{ []byte("\x06\b*\x86H\xce=\x03\x01\a0\xd80r0"), []byte("\x06\b*\x86H\xce=\x03\x01\a\f\x1cEnigmaCh" + "ain Node Ce000000000"), diff --git a/x/registration/remote_attestation/remote_attestation.go b/x/registration/remote_attestation/remote_attestation.go index 6d345614a..e63ade54f 100644 --- a/x/registration/remote_attestation/remote_attestation.go +++ b/x/registration/remote_attestation/remote_attestation.go @@ -7,8 +7,9 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/pkg/errors" "time" + + "github.com/pkg/errors" ) /* @@ -134,7 +135,7 @@ func verifyCert(payload []byte) ([]byte, error) { // note: there's no way to not validate the time, and we don't want to write this code // ourselves. We also can't just ignore the error message, since that means that the rest of // the validation didn't happen (time is validated early on) - CurrentTime: time.Date(2023, 11, 04, 00, 00, 00, 00, time.UTC), + CurrentTime: time.Date(2023, 11, 0o4, 0o0, 0o0, 0o0, 0o0, time.UTC), } if _, err := certServer.Verify(opts); err != nil { @@ -159,11 +160,11 @@ func verifyAttReport(attnReportRaw []byte, pubK []byte) ([]byte, error) { // 1. Check timestamp is within 24H if qr.Timestamp != "" { - //timeFixed := qr.Timestamp + "+0000" - //timeFixed := qr.Timestamp + "Z" - //ts, _ := time.Parse(time.RFC3339, timeFixed) - //now := time.Now().Unix() - //fmt.Println("Time diff = ", now-ts.Unix()) + // timeFixed := qr.Timestamp + "+0000" + // timeFixed := qr.Timestamp + "Z" + // ts, _ := time.Parse(time.RFC3339, timeFixed) + // now := time.Now().Unix() + // fmt.Println("Time diff = ", now-ts.Unix()) } else { return nil, errors.New("Failed to fetch timestamp from attestation report") } @@ -171,7 +172,7 @@ func verifyAttReport(attnReportRaw []byte, pubK []byte) ([]byte, error) { // 2. Verify quote status (mandatory field) if qr.IsvEnclaveQuoteStatus != "" { - //fmt.Println("isvEnclaveQuoteStatus = ", qr.IsvEnclaveQuoteStatus) + // fmt.Println("isvEnclaveQuoteStatus = ", qr.IsvEnclaveQuoteStatus) switch qr.IsvEnclaveQuoteStatus { case "OK": break @@ -240,13 +241,13 @@ func verifyAttReport(attnReportRaw []byte, pubK []byte) ([]byte, error) { qrData := parseReport(qb, quoteHex) // todo: possibly verify mr signer/enclave? - //fmt.Println("Quote = [" + quoteBytes[:len(quoteBytes)-2] + "]") - //fmt.Println("sgx quote version = ", qrData.version) - //fmt.Println("sgx quote signature type = ", qrData.signType) - //fmt.Println("sgx quote report_data = ", qrData.reportBody.reportData) - //fmt.Println("sgx quote mr_enclave = ", qrData.reportBody.mrEnclave) - //fmt.Println("sgx quote mr_signer = ", qrData.reportBody.mrSigner) - //fmt.Println("Anticipated public key = ", pubHex) + // fmt.Println("Quote = [" + quoteBytes[:len(quoteBytes)-2] + "]") + // fmt.Println("sgx quote version = ", qrData.version) + // fmt.Println("sgx quote signature type = ", qrData.signType) + // fmt.Println("sgx quote report_data = ", qrData.reportBody.reportData) + // fmt.Println("sgx quote mr_enclave = ", qrData.reportBody.mrEnclave) + // fmt.Println("sgx quote mr_signer = ", qrData.reportBody.mrSigner) + // fmt.Println("Anticipated public key = ", pubHex) if qrData.ReportBody.ReportData != pubHex { // err := errors.New("Failed to authenticate certificate public key")