Skip to content

Commit

Permalink
contract error update and log fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dixitaniket committed Aug 17, 2023
1 parent 17491e9 commit 5aa1117
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 93 deletions.
77 changes: 14 additions & 63 deletions cosmwasm/contracts/price-feed/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ fn execute_relay(
// Checks if sender is a relayer
let sender_addr = &info.sender;
if !query_is_relayer(deps.as_ref(), sender_addr)? {
return Err(ContractError::Unauthorized {
msg: String::from("Sender is not a relayer"),
});
return Err(ContractError::UnauthorizedRelayer {});
}

// Saves price data
Expand Down Expand Up @@ -175,9 +173,7 @@ fn execute_relay_historical_median(
// Checks if sender is a relayer
let sender_addr = &info.sender;
if !query_is_relayer(deps.as_ref(), sender_addr)? {
return Err(ContractError::Unauthorized {
msg: String::from("Sender is not a relayer"),
});
return Err(ContractError::UnauthorizedRelayer {});
}

if !MEDIANSTATUS.load(deps.storage)? {
Expand Down Expand Up @@ -212,9 +208,7 @@ fn execute_force_relay(
let sender_addr = &info.sender;

if !query_is_relayer(deps.as_ref(), sender_addr)? {
return Err(ContractError::Unauthorized {
msg: String::from("Sender is not a relayer"),
});
return Err(ContractError::UnauthorizedRelayer {});
}

for (symbol, rate) in symbol_rates {
Expand All @@ -238,9 +232,7 @@ fn execute_force_relay_historical_median(
let sender_addr = &info.sender;

if !query_is_relayer(deps.as_ref(), sender_addr)? {
return Err(ContractError::Unauthorized {
msg: String::from("Sender is not a relayer"),
});
return Err(ContractError::UnauthorizedRelayer {});
}

for (symbol, rates) in symbol_rates {
Expand All @@ -264,9 +256,7 @@ fn execute_relay_historical_deviation(
// Checks if sender is a relayer
let sender_addr = &info.sender;
if !query_is_relayer(deps.as_ref(), sender_addr)? {
return Err(ContractError::Unauthorized {
msg: String::from("Sender is not a relayer"),
});
return Err(ContractError::UnauthorizedRelayer {});
}

// Saves price data
Expand Down Expand Up @@ -297,9 +287,7 @@ fn execute_force_relay_historical_deviation(
// Checks if sender is a relayer
let sender_addr = &info.sender;
if !query_is_relayer(deps.as_ref(), sender_addr)? {
return Err(ContractError::Unauthorized {
msg: String::from("Sender is not a relayer"),
});
return Err(ContractError::UnauthorizedRelayer {});
}

// Saves price data
Expand Down Expand Up @@ -379,9 +367,7 @@ fn query_reference_data_bulk(

fn assert_admin(config_admin: &Addr, account: &Addr) -> Result<(), ContractError> {
if config_admin != account {
return Err(ContractError::Admin {
msg: String::from("ADMIN ONLY"),
});
return Err(ContractError::UnauthorizedAdmin {});
}

Ok(())
Expand Down Expand Up @@ -539,12 +525,7 @@ mod tests {
let err = execute(deps.as_mut(), env, info, msg);
assert_eq!(err.is_err(), true);

assert_eq!(
err.err().unwrap(),
ContractError::Admin {
msg: String::from("ADMIN ONLY"),
}
)
assert_eq!(err.unwrap_err(), ContractError::UnauthorizedAdmin {})
}

#[test]
Expand Down Expand Up @@ -610,12 +591,7 @@ mod tests {
let msg = ExecuteMsg::MedianStatus { status: true };

let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(
err,
ContractError::Admin {
msg: String::from("ADMIN ONLY"),
}
)
assert_eq!(err, ContractError::UnauthorizedAdmin {})
}

#[test]
Expand All @@ -634,12 +610,7 @@ mod tests {
relayers: vec![String::from("relayer_1")],
};
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(
err,
ContractError::Admin {
msg: String::from("ADMIN ONLY"),
}
)
assert_eq!(err, ContractError::UnauthorizedAdmin {})
}

#[test]
Expand Down Expand Up @@ -687,12 +658,7 @@ mod tests {
let msg = RemoveRelayers { relayers };
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();

assert_eq!(
err,
ContractError::Admin {
msg: String::from("ADMIN ONLY"),
}
);
assert_eq!(err, ContractError::UnauthorizedAdmin {});
}

#[test]
Expand Down Expand Up @@ -1146,12 +1112,7 @@ mod tests {
request_id: Uint64::zero(),
};
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(
err,
ContractError::Unauthorized {
msg: String::from("Sender is not a relayer")
}
);
assert_eq!(err, ContractError::UnauthorizedRelayer {});
}

#[test]
Expand Down Expand Up @@ -1242,12 +1203,7 @@ mod tests {
request_id: Uint64::zero(),
};
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(
err,
ContractError::Unauthorized {
msg: String::from("Sender is not a relayer")
}
);
assert_eq!(err, ContractError::UnauthorizedRelayer {});
}
}

Expand Down Expand Up @@ -1276,12 +1232,7 @@ mod tests {

assert_eq!(is_admin.is_err(), true,);

assert_eq!(
is_admin.err().unwrap(),
ContractError::Admin {
msg: String::from("ADMIN ONLY"),
}
)
assert_eq!(is_admin.err().unwrap(), ContractError::UnauthorizedAdmin {})
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions cosmwasm/contracts/price-feed/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("Unauthorized: {msg}")]
Admin { msg: String },
#[error("Unauthorized: sender is not an admin")]
UnauthorizedAdmin {},

#[error("Unauthorized: {msg}")]
Unauthorized { msg: String },
#[error("Unauthorized: sender is not relayer")]
UnauthorizedRelayer {},

#[error("Median is disabled")]
MedianDisabled {},
Expand Down
14 changes: 7 additions & 7 deletions cw-relayer/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
contract_address = "secret1vghu442e4n90836xr40fccdgrypqt4spd8tdzw"
contract_address = "secret1aa8c3mxwu5kpcd8hlmkvjhzhqu37q8cj6eapyz"

# relayer changes rpcs (event and query) in the order specified in config
# query rpcs for prices
Expand All @@ -18,7 +18,7 @@ query_timeout = "3000ms"
max_retries = 1

timeout_height = 10
resolve_duration = "1000ms"
resolve_duration = "20000ms"
missed_threshold = 5
# default median data and ref request id at start/restart
median_request_id = 1
Expand All @@ -30,8 +30,8 @@ ignore_median_errors= false


gas_prices = "0.15uscrt"
code_hash = "125c44ec8884a412d596dbf40c59c14b010f6803eee0d3113f1e60a308cda126"
gas_limit = "102850"
code_hash = "287b53f3f5e70c3ec8a60aa0147374100d4a42770d6bae1d2fcac50bd7ce4691"
gas_limit = "855078"

# restart config
[restart]
Expand All @@ -44,7 +44,7 @@ skip_error = false
### account & chain-id for the wasmd relayer account
[account]
address = "secret19uywplnd25gzxgc3t8pyqsl2tcse8heag2s6av"
chain_id = "pulsar-2"
chain_id = "pulsar-3"
acc_prefix = "secret"

### keyring for the relayer account on the wasmd chain
Expand All @@ -55,5 +55,5 @@ dir = "./"
### rpc endpoint for the wasm Chain
[rpc]
rpc_timeout = "5000ms"
query_endpoint = "grpcbin.pulsar.scrttestnet.com:9099"
tmrpc_endpoint = "https://rpc.pulsar.scrttestnet.com:443"
query_endpoint = "grpcbin.pulsar3.scrttestnet.com:9099"
tmrpc_endpoint = "https://rpc.pulsar3.scrttestnet.com:443"
1 change: 1 addition & 0 deletions cw-relayer/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ func (r *Relayer) tick(ctx context.Context) error {
executeMsgs[i] = &executeMsg
}

logs.Msg("broadcasting tx")
if err := r.relayerClient.BroadcastTx(*clientCtx, r.resolveDuration, nextBlockHeight, r.timeoutHeight, executeMsgs...); err != nil {
r.missedCounter += 1
return err
Expand Down
31 changes: 12 additions & 19 deletions scripts/deploy_contract.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
BINARY=secretcli
CHAINID_1="pulsar-2"
CHAINID_1="pulsar-3"
CONTRACT_PATH=./cosmwasm/artifacts/std_reference.wasm
RPC="https://rpc.testnet.secretsaturn.net"
RPC="https://rpc.pulsar3.scrttestnet.com:443"
NODE="--node $RPC"
TXFLAG="$NODE --chain-id $CHAINID_1 --gas-prices 1uscrt --gas-adjustment 1.3"
TXFLAG="$NODE --chain-id $CHAINID_1 --gas-prices 1uscrt --gas-adjustment 1.3 --broadcast-mode block --gas auto"

export DEMOWALLET=$($BINARY keys show relayer -a --keyring-backend=test --keyring-dir=./relayer-data/ ) && echo $DEMOWALLET;
$BINARY query wasm list-code $NODE
export DEMOWALLET=$($BINARY keys show relayer2 -a --keyring-backend=test ) && echo $DEMOWALLET;

# deploy smart contract
$BINARY tx compute store $CONTRACT_PATH --from $DEMOWALLET --keyring-backend=test --keyring-dir=./cw-relayer/data/ $TXFLAG -y
sleep 5

$BINARY tx compute instantiate 19480 '{}' --label=newtest --from $DEMOWALLET --keyring-backend=test --keyring-dir=./cw-relayer/data/ -y
sleep 5
$BINARY tx compute store $CONTRACT_PATH --from $DEMOWALLET --keyring-backend=test $TXFLAG -y

#instantiate contract
$BINARY tx compute instantiate 1 '{}' --label=newthings --from $DEMOWALLET --keyring-backend=test --keyring-dir=./cw-relayer/newrelayerdata/ --sign-mode=direct $TXFLAG -y
sleep 5
$BINARY tx compute instantiate 1 '{}' --label=test --from $DEMOWALLET --keyring-backend=test -y

## query contract address
CONTRACT=$($BINARY query compute list-contract-by-code "19480" $NODE --output json | jq -r '.[0].contract_address')
# query contract address
CONTRACT=$($BINARY query compute list-contract-by-code "1" $NODE --output json | jq -r '.[0].contract_address')
echo $CONTRACT

#sample
#adding relayer
ADD_RELAYERS='{"add_relayers": {"relayers": ["secret19uywplnd25gzxgc3t8pyqsl2tcse8heag2s6av"]}}'
$BINARY tx compute execute $CONTRACT "$ADD_RELAYERS" --keyring-dir=./relayer-data --keyring-backend=test --from $DEMOWALLET --dry-run -y
sleep 5
$BINARY tx compute execute $CONTRACT "$ADD_RELAYERS" --from $DEMOWALLET --keyring-backend=test $TXFLAG -y

#sample price tx
RELAY='{"force_relay": {"symbol_rates": [["ATOM","14"]], "resolve_time":"10", "request_id":"2"}}'
$BINARY tx compute execute $CONTRACT "$RELAY" --keyring-backend=test --keyring-dir=./cw-relayer/data/ --sign-mode=direct --from $DEMOWALLET $TXFLAG --offline
sleep 5
$BINARY tx compute execute $CONTRACT "$RELAY" --keyring-backend=test --sign-mode=direct --from $DEMOWALLET $TXFLAG

QUERY='{"get_ref": {"symbol": "ATOM"}}'
$BINARY query compute query $CONTRACT "$QUERY" $NODE --output json

0 comments on commit 5aa1117

Please sign in to comment.