Skip to content

Commit

Permalink
fix: deposit stake withdraw test
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed May 7, 2024
1 parent e96efbd commit 94c0c5c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
12 changes: 6 additions & 6 deletions packages/integration-tests/src/data_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use proxy_contract::msg::{ProxyExecuteMsg, ProxyQueryMsg};
fn commit_reveal_result() {
let (mut app, proxy_contract) = proper_instantiate();

let mut exec_1 = TestExecutor::new("exec_1");
let mut exec_2 = TestExecutor::new("exec_2");
let mut exec_3 = TestExecutor::new("exec_3");
let exec_1 = TestExecutor::new("exec_1");
let exec_2 = TestExecutor::new("exec_2");
let exec_3 = TestExecutor::new("exec_3");

// executor 1 should be ineligible to register
let msg = ProxyQueryMsg::IsDataRequestExecutorEligible {
Expand All @@ -41,9 +41,9 @@ fn commit_reveal_result() {

// register executors
let memo = Some("address".to_string());
helper_reg_dr_executor(&mut app, proxy_contract.clone(), &mut exec_1, memo.clone()).unwrap();
helper_reg_dr_executor(&mut app, proxy_contract.clone(), &mut exec_2, memo.clone()).unwrap();
helper_reg_dr_executor(&mut app, proxy_contract.clone(), &mut exec_3, memo.clone()).unwrap();
helper_reg_dr_executor(&mut app, proxy_contract.clone(), &exec_1, memo.clone()).unwrap();
helper_reg_dr_executor(&mut app, proxy_contract.clone(), &exec_2, memo.clone()).unwrap();
helper_reg_dr_executor(&mut app, proxy_contract.clone(), &exec_3, memo.clone()).unwrap();

// check if executors are eligible register
// executor 1 should be eligible to register
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sha3::{Digest, Keccak256};

#[test]
pub fn recover_pub_key_from_sig() {
let mut executor = TestExecutor::new("test");
let executor = TestExecutor::new("test");

let mut hasher = Keccak256::new();
hasher.update("hello world".as_bytes());
Expand Down
44 changes: 23 additions & 21 deletions packages/integration-tests/src/staking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::tests::utils::{proper_instantiate, send_tokens, EXECUTOR_1, NATIVE_DENOM, USER};
use crate::tests::utils::{proper_instantiate, send_tokens, TestExecutor, NATIVE_DENOM, USER};

use common::{msg::GetDataRequestExecutorResponse, state::DataRequestExecutor, types::Signature};
use common::{msg::GetDataRequestExecutorResponse, state::DataRequestExecutor};
use cosmwasm_std::Addr;
use cw_multi_test::Executor;

Expand All @@ -11,23 +11,25 @@ use proxy_contract::msg::{ProxyExecuteMsg, ProxyQueryMsg};
fn deposit_stake_withdraw() {
let (mut app, proxy_contract) = proper_instantiate();

let exec = TestExecutor::new("foo");

// send tokens from USER to executor1 so it can register
send_tokens(&mut app, USER, EXECUTOR_1, 3);
send_tokens(&mut app, USER, exec.name, 3);

let msg = ProxyExecuteMsg::RegisterDataRequestExecutor {
memo: Some("address".to_string()),
public_key: vec![],
signature: Signature::new([0; 65]),
public_key: exec.public_key.clone(),
signature: exec.sign(["register_data_request_executor".as_bytes().to_vec()]),
};
let cosmos_msg = proxy_contract
.call_with_deposit(msg, INITIAL_MINIMUM_STAKE_TO_REGISTER)
.unwrap();
// register executor
app.execute(Addr::unchecked(EXECUTOR_1), cosmos_msg.clone())
app.execute(Addr::unchecked(exec.name), cosmos_msg.clone())
.unwrap();

let msg = ProxyQueryMsg::GetDataRequestExecutor {
executor: Addr::unchecked(EXECUTOR_1),
executor: exec.public_key.clone(),
};
let res: GetDataRequestExecutorResponse = app
.wrap()
Expand All @@ -47,15 +49,15 @@ fn deposit_stake_withdraw() {

// deposit 2 more
let msg = ProxyExecuteMsg::DepositAndStake {
public_key: vec![],
signature: Signature::new([0; 65]),
public_key: exec.public_key.clone(),
signature: exec.sign(["deposit_and_stake".as_bytes().to_vec()]),
};
let cosmos_msg = proxy_contract.call_with_deposit(msg, 2).unwrap();
app.execute(Addr::unchecked(EXECUTOR_1), cosmos_msg.clone())
app.execute(Addr::unchecked(exec.name), cosmos_msg.clone())
.unwrap();

let msg = ProxyQueryMsg::GetDataRequestExecutor {
executor: Addr::unchecked(EXECUTOR_1),
executor: exec.public_key.clone(),
};
let res: GetDataRequestExecutorResponse = app
.wrap()
Expand All @@ -76,15 +78,15 @@ fn deposit_stake_withdraw() {
// unstake 2
let msg = ProxyExecuteMsg::Unstake {
amount: 2,
public_key: vec![],
signature: Signature::new([0; 65]),
public_key: exec.public_key.clone(),
signature: exec.sign(["unstake".as_bytes().to_vec()]),
};
let cosmos_msg = proxy_contract.call(msg).unwrap();
app.execute(Addr::unchecked(EXECUTOR_1), cosmos_msg.clone())
app.execute(Addr::unchecked(exec.name), cosmos_msg.clone())
.unwrap();

let msg = ProxyQueryMsg::GetDataRequestExecutor {
executor: Addr::unchecked(EXECUTOR_1),
executor: exec.public_key.clone(),
};
let res: GetDataRequestExecutorResponse = app
.wrap()
Expand All @@ -104,7 +106,7 @@ fn deposit_stake_withdraw() {

let balance_before = app
.wrap()
.query_balance(EXECUTOR_1, NATIVE_DENOM)
.query_balance(exec.name, NATIVE_DENOM)
.unwrap()
.amount
.u128();
Expand All @@ -113,15 +115,15 @@ fn deposit_stake_withdraw() {
// withdraw 2
let msg = ProxyExecuteMsg::Withdraw {
amount: 2,
public_key: vec![],
signature: Signature::new([0; 65]),
public_key: exec.public_key.clone(),
signature: exec.sign(["withdraw".as_bytes().to_vec()]),
};
let cosmos_msg = proxy_contract.call(msg).unwrap();
app.execute(Addr::unchecked(EXECUTOR_1), cosmos_msg.clone())
app.execute(Addr::unchecked(exec.name), cosmos_msg.clone())
.unwrap();

let msg = ProxyQueryMsg::GetDataRequestExecutor {
executor: Addr::unchecked(EXECUTOR_1),
executor: exec.public_key.clone(),
};
let res: GetDataRequestExecutorResponse = app
.wrap()
Expand All @@ -141,7 +143,7 @@ fn deposit_stake_withdraw() {

let balance_after = app
.wrap()
.query_balance(EXECUTOR_1, NATIVE_DENOM)
.query_balance(exec.name, NATIVE_DENOM)
.unwrap()
.amount
.u128();
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TestExecutor {
hasher.finalize().into()
}

pub fn sign<I>(&mut self, msg: I) -> Signature
pub fn sign<I>(&self, msg: I) -> Signature
where
I: IntoIterator<Item = Vec<u8>>,
{
Expand Down Expand Up @@ -291,7 +291,7 @@ pub fn reveal_hash(reveal: &RevealBody, salt: Option<&'static str>) -> (Hash, Ve
pub fn helper_reg_dr_executor(
app: &mut App,
proxy_contract: CwTemplateContract,
executor: &mut TestExecutor,
executor: &TestExecutor,
memo: Option<String>,
) -> Result<AppResponse, anyhow::Error> {
let contract_call_bytes = "register_data_request_executor".as_bytes().to_vec();
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub enum ProxyQueryMsg {

// Staking
#[returns(GetDataRequestExecutorResponse)]
GetDataRequestExecutor { executor: Addr },
GetDataRequestExecutor { executor: Secpk256k1PublicKey },
#[returns(IsDataRequestExecutorEligibleResponse)]
IsDataRequestExecutorEligible { executor: Secpk256k1PublicKey },
#[returns(GetStakingConfigResponse)]
Expand Down

0 comments on commit 94c0c5c

Please sign in to comment.