Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandrejev committed Dec 7, 2023
1 parent 49307b2 commit 11a4939
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 21 deletions.
2 changes: 1 addition & 1 deletion contracts/ibc_transfer/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
integration-test = "test --test integration"
schema = "run --example schema"
schema = "run --bin ibc_transfer_schema"
1 change: 1 addition & 0 deletions contracts/ibc_transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ schemars = { workspace = true }
serde = { workspace = true }
serde-json-wasm = { workspace = true }
cw-storage-plus = { workspace = true, features = ["iterator"]}
cosmwasm-schema = { workspace = true }
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }

[dev-dependencies]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_queries/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
integration-test = "test --test integration"
schema = "run --example schema"
schema = "run --bin neutron_interchain_queries_schema"
4 changes: 3 additions & 1 deletion contracts/neutron_interchain_queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
cosmos-sdk-proto = { workspace = true }
cw-storage-plus = { workspace = true }
serde-json-wasm = { workspace = true }
prost-types = { workspace = true }
cosmwasm-schema = { workspace = true }

[dev-dependencies]
base64 = { workspace = true }
cosmwasm-schema = { workspace = true }

16 changes: 8 additions & 8 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,18 @@ pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> NeutronResult
QueryMsg::BankTotalSupply { query_id } => {
Ok(to_json_binary(&query_bank_total(deps, env, query_id)?)?)
}
QueryMsg::DistributionFeePool { query_id } => Ok(to_binary(&query_distribution_fee_pool(
QueryMsg::DistributionFeePool { query_id } => Ok(to_json_binary(
&query_distribution_fee_pool(deps, env, query_id)?,
)?),
QueryMsg::StakingValidators { query_id } => Ok(to_json_binary(&query_staking_validators(
deps, env, query_id,
)?)?),
QueryMsg::StakingValidators { query_id } => {
Ok(to_binary(&query_staking_validators(deps, env, query_id)?)?)
}
QueryMsg::ValidatorsSigningInfos { query_id } => Ok(to_binary(
QueryMsg::ValidatorsSigningInfos { query_id } => Ok(to_json_binary(
&query_validators_signing_infos(deps, env, query_id)?,
)?),
QueryMsg::GovernmentProposals { query_id } => Ok(to_binary(&query_government_proposals(
deps, env, query_id,
)?)?),
QueryMsg::GovernmentProposals { query_id } => Ok(to_json_binary(
&query_government_proposals(deps, env, query_id)?,
)?),
QueryMsg::GetDelegations { query_id } => {
Ok(to_json_binary(&query_delegations(deps, env, query_id)?)?)
}
Expand Down
109 changes: 106 additions & 3 deletions contracts/neutron_interchain_queries/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use cosmos_sdk_proto::cosmos::distribution::v1beta1::FeePool as CosmosFeePool;
use cosmos_sdk_proto::cosmos::gov::v1beta1::{
Proposal as CosmosProposal, TallyResult as CosmosTallyResult,
};
use cosmos_sdk_proto::cosmos::slashing::v1beta1::ValidatorSigningInfo as CosmosValidatorSigningInfo;
use cosmos_sdk_proto::cosmos::staking::v1beta1::Validator as CosmosValidator;
use cosmos_sdk_proto::traits::Message;
use cosmos_sdk_proto::Any;
Expand All @@ -34,13 +35,13 @@ use neutron_sdk::interchain_queries::v045::helpers::{
create_total_denom_key, create_validator_key,
};
use neutron_sdk::interchain_queries::v045::types::{
Balances, FeePool, GovernmentProposal, Proposal, StakingValidator, TallyResult, TotalSupply,
Validator, RECIPIENT_FIELD,
Balances, FeePool, GovernmentProposal, Proposal, SigningInfo, StakingValidator, TallyResult,
TotalSupply, Validator, ValidatorSigningInfo, RECIPIENT_FIELD,
};

use neutron_sdk::interchain_queries::v045::queries::{
BalanceResponse, DelegatorDelegationsResponse, FeePoolResponse, ProposalResponse,
TotalSupplyResponse, ValidatorResponse,
TotalSupplyResponse, ValidatorResponse, ValidatorSigningInfoResponse,
};
use neutron_sdk::NeutronError;
use schemars::_serde_json::to_string;
Expand Down Expand Up @@ -155,6 +156,29 @@ fn build_interchain_query_staking_validator_value(validator: String) -> StorageV
}
}

fn build_interchain_query_validator_signing_info_value(
validator: String,
jailed_until: Option<prost_types::Timestamp>,
) -> StorageValue {
let operator_address = decode_and_convert(validator.as_str()).unwrap();
let validator_key = create_validator_key(operator_address).unwrap();

let validator = CosmosValidatorSigningInfo {
address: validator,
start_height: 1,
index_offset: 20,
jailed_until,
tombstoned: false,
missed_blocks_counter: 13,
};

StorageValue {
storage_prefix: "".to_string(),
key: Binary(validator_key),
value: Binary(validator.encode_to_vec()),
}
}

fn build_interchain_query_gov_proposal_value(proposal_id: u64) -> StorageValue {
let proposal_key = create_gov_proposal_key(proposal_id).unwrap();

Expand Down Expand Up @@ -517,6 +541,7 @@ fn test_staking_validators_query() {
operator_address: "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w"
.to_string(),
status: 1,
consensus_pubkey: Some(vec!()),
tokens: "1".to_string(),
jailed: false,
delegator_shares: "1".to_string(),
Expand All @@ -537,6 +562,7 @@ fn test_staking_validators_query() {
operator_address: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0"
.to_string(),
status: 1,
consensus_pubkey: Some(vec!()),
tokens: "1".to_string(),
jailed: false,
delegator_shares: "1".to_string(),
Expand All @@ -559,6 +585,83 @@ fn test_staking_validators_query() {
)
}

#[test]
fn test_validators_signing_infos_query() {
let mut deps = dependencies(&[]);
let validators = vec![
(
"cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w".to_string(),
None,
),
(
"cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0".to_string(),
Some(prost_types::Timestamp {
seconds: 1203981203,
nanos: 123123,
}),
),
];

let msg = ExecuteMsg::RegisterValidatorsSigningInfosQuery {
connection_id: "connection".to_string(),
update_period: 10,
validators: validators.clone().into_iter().map(|(v, _)| v).collect(),
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);

let mut kv_results: Vec<StorageValue> = vec![];

for validator in validators {
let value = build_interchain_query_validator_signing_info_value(validator.0, validator.1);
kv_results.push(value);
}

let validators_response = QueryRegisteredQueryResultResponse {
result: InterchainQueryResult {
kv_results,
height: 0,
revision: 0,
},
};

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, to_json_binary(&validators_response).unwrap());
let staking_validators = QueryMsg::ValidatorsSigningInfos { query_id: 1 };
let resp: ValidatorSigningInfoResponse =
from_json(query(deps.as_ref(), mock_env(), staking_validators).unwrap()).unwrap();
assert_eq!(
resp,
ValidatorSigningInfoResponse {
last_submitted_local_height: 987,
signing_infos: SigningInfo {
signing_infos: vec![
ValidatorSigningInfo {
address: "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w".to_string(),
start_height: 1,
index_offset: 20,
jailed_until: None,
tombstoned: false,
missed_blocks_counter: 13
},
ValidatorSigningInfo {
address: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0".to_string(),
start_height: 1,
index_offset: 20,
jailed_until: Some(1203981203),
tombstoned: false,
missed_blocks_counter: 13,
}
]
}
}
)
}

#[test]
fn test_query_delegator_delegations() {
let mut deps = dependencies(&[]);
Expand Down
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_txs/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
integration-test = "test --test integration"
schema = "run --example schema"
schema = "run --bin neutron_interchain_txs_schema"
3 changes: 1 addition & 2 deletions contracts/neutron_interchain_txs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ cw-storage-plus = { workspace = true }
cosmos-sdk-proto = { workspace = true }
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
prost-types = { workspace = true }

[dev-dependencies]
cosmwasm-schema = { workspace = true }

2 changes: 1 addition & 1 deletion packages/neutron-sdk/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --bin schema"
schema = "run --bin neutron-sdk-schema"
8 changes: 5 additions & 3 deletions packages/neutron-sdk/schema/neutron_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"type": "object",
"required": [
"connection_id",
"interchain_account_id",
"register_fee"
"interchain_account_id"
],
"properties": {
"connection_id": {
Expand All @@ -28,7 +27,10 @@
},
"register_fee": {
"description": "*register_fee** is a fees required to be payed to register interchain account",
"type": "array",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Coin"
}
Expand Down
File renamed without changes.

0 comments on commit 11a4939

Please sign in to comment.