Skip to content

Commit

Permalink
Merge branch 'develop' into chore/deploy-proxy-args
Browse files Browse the repository at this point in the history
* develop:
  change env naming convention (#155)
  Add a hello-world consumer example (#143)
  Add gauntlet e2e tests through accepting a proposal (#141)
  add ocr2 spec changes, switch image repo (#152)
  additional unit tests for remaining proxy functions (#149)
  Document lack of transmitters prefix (#150)
  • Loading branch information
momentmaker committed Feb 25, 2022
2 parents b8420b8 + 9333b56 commit aa41906
Show file tree
Hide file tree
Showing 31 changed files with 1,198 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ on:
type: string
cl_repo:
required: true
default: 795953128386.dkr.ecr.us-west-2.amazonaws.com/chainlink
default: public.ecr.aws/z0b1w9r9/chainlink
type: string
cl_image:
required: true
default: develop.latest
default: develop
type: string
secrets:
QA_AWS_ACCESS_KEY_ID:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ bin
packages-ts/gauntlet-terra-contracts/codeIds/test*
packages-ts/gauntlet-terra-contracts/networks/.env.test*
tests/e2e/logs
networks/.env.test*
packages-ts/gauntlet-terra-contracts/networks/.env.test*
tests/e2e/smoke/rdd/directory*
tests/e2e/smoke/reports
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

members = [
"contracts/*",
"crates/*"
"crates/*",
"examples/hello-world",
]

[profile.dev]
Expand Down
3 changes: 3 additions & 0 deletions contracts/ocr2/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ pub fn execute_propose_config(
// validate new config
require!(f != 0, InvalidInput);
require!(signers_len <= MAX_ORACLES, TooManySigners);
// See corresponding comment https://github.com/smartcontractkit/chainlink-terra/blob/5c229358eea2633922de615be509eb47c5bcb998/pkg/terra/config_digester.go#L30
// If this requirement of len(transmitters) == len(signers) is removed, we'll need
// to update the config digester to include a length prefix on transmitters.
require!(transmitters.len() == signers.len(), InvalidInput);
require!(payees.len() == signers.len(), InvalidInput);
require!(3 * (usize::from(f)) < signers_len, InvalidInput);
Expand Down
152 changes: 149 additions & 3 deletions contracts/proxy-ocr2/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod mock {
match msg {
ExecuteMsg::Insert(round) => {
let round_id = LATEST_ROUND
.update(deps.storage, |round_id: u32| StdResult::Ok(round_id + 1))?;
.update(deps.storage, |_: u32| StdResult::Ok(round.round_id))?; // store data based on passed in round_id
ROUNDS.save(deps.storage, round_id.into(), &round)?;
Ok(Response::default())
}
Expand Down Expand Up @@ -283,7 +283,43 @@ fn it_works() {

assert_eq!(proposed_latest_round.round_id, 3);

// confirm it
// (proposed) query by round id, it should match latest round
let proposed_round: Round = env
.router
.wrap()
.query_wasm_smart(
&env.proxy_addr,
&QueryMsg::ProposedRoundData {
round_id: proposed_latest_round.round_id as u32,
},
)
.unwrap();
assert_eq!(proposed_round, proposed_latest_round);

// store old aggregator address
let old_aggregator: String = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::Aggregator)
.unwrap();
assert_eq!(env.ocr2_addr.to_string(), old_aggregator);

// store old aggregator address
let proposed_aggregator: String = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::ProposedAggregator)
.unwrap();
assert_eq!(ocr2_addr2.to_string(), proposed_aggregator);

// save original phase
let old_phase: u16 = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::PhaseId)
.unwrap();

// confirm aggregator swap
env.router
.execute_contract(
env.owner.clone(),
Expand All @@ -295,7 +331,46 @@ fn it_works() {
)
.unwrap();

// query latest round, it should now point to the new aggregator
// fetch new aggregator address
let new_aggregator: String = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::Aggregator)
.unwrap();
assert_ne!(old_aggregator, new_aggregator);
assert_eq!(ocr2_addr2.to_string(), new_aggregator);
assert_eq!(proposed_aggregator, new_aggregator);

// check phase details after switching
let new_phase: u16 = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::PhaseId)
.unwrap();
assert_ne!(old_phase, new_phase);
let old_phase_agg: String = env
.router
.wrap()
.query_wasm_smart(
&env.proxy_addr,
&QueryMsg::PhaseAggregators {
phase_id: old_phase,
},
)
.unwrap();
let new_phase_agg: String = env
.router
.wrap()
.query_wasm_smart(
&env.proxy_addr,
&QueryMsg::PhaseAggregators {
phase_id: new_phase,
},
)
.unwrap();
assert_eq!(old_aggregator, old_phase_agg);
assert_eq!(new_aggregator, new_phase_agg);

let latest_round: Round = env
.router
.wrap()
Expand All @@ -316,4 +391,75 @@ fn it_works() {
.unwrap();

assert_eq!(round, historic_round);

// test ownership transfer
let old_owner: String = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::Owner)
.unwrap();
let owner2 = Addr::unchecked("new_owner");
// cannot transfer if not owner
assert!(env
.router
.execute_contract(
owner2.clone(),
env.proxy_addr.clone(),
&ExecuteMsg::TransferOwnership {
to: owner2.to_string(),
},
&[],
)
.is_err());
// owner can transfer ownership
assert!(env
.router
.execute_contract(
env.owner.clone(),
env.proxy_addr.clone(),
&ExecuteMsg::TransferOwnership {
to: env.owner.to_string(),
},
&[],
)
.is_ok());
// owner can transfer ownership again (overwrite pending)
assert!(env
.router
.execute_contract(
env.owner.clone(),
env.proxy_addr.clone(),
&ExecuteMsg::TransferOwnership {
to: owner2.to_string(),
},
&[],
)
.is_ok());
// current owner cannot accept ownership of new owner
assert!(env
.router
.execute_contract(
env.owner.clone(),
env.proxy_addr.clone(),
&ExecuteMsg::AcceptOwnership,
&[],
)
.is_err());
// new owner can accept ownership
assert!(env
.router
.execute_contract(
owner2.clone(),
env.proxy_addr.clone(),
&ExecuteMsg::AcceptOwnership,
&[],
)
.is_ok());
let new_owner: String = env
.router
.wrap()
.query_wasm_smart(&env.proxy_addr, &QueryMsg::Owner)
.unwrap();
assert_ne!(old_owner, new_owner);
assert_eq!(owner2.to_string(), new_owner);
}
30 changes: 30 additions & 0 deletions examples/hello-world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "hello-world"
version = "0.1.0"
authors = ["Blaž Hrastnik <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-std = { version = "0.16.2" }
cosmwasm-storage = { version = "0.16.0" }
cw-storage-plus = "0.9.0"
cw2 = "0.9.0"
schemars = "0.8.3"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.24" }

chainlink-terra = { version = "0.1.0", package = "proxy-ocr2", path = "../../contracts/proxy-ocr2", default-features = false, features = ["library"] }

[dev-dependencies]
cosmwasm-schema = { version = "0.16.0" }
cw-multi-test = "0.9.1"
1 change: 1 addition & 0 deletions examples/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Chainlink Hello World Example
17 changes: 17 additions & 0 deletions examples/hello-world/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

use hello_world::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
}
Loading

0 comments on commit aa41906

Please sign in to comment.