Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fireblock tests to CI #120

Merged
merged 35 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fee9b77
add coverage to makefile and ci integration
TomasArrachea Aug 30, 2024
e1151ae
remove codecov upload
TomasArrachea Sep 2, 2024
398b927
remove foundry from ci and add coverage comment
TomasArrachea Sep 2, 2024
b502c7f
replace comment action with upload artifact
TomasArrachea Sep 2, 2024
3deeaa7
fix integration.yml
TomasArrachea Sep 2, 2024
2b0f03a
update to upload-artifact v4
TomasArrachea Sep 2, 2024
d3c26b6
remove clippy and fmt from CI
TomasArrachea Sep 2, 2024
b13ad1c
install lcov in ci
TomasArrachea Sep 2, 2024
f13f2b1
add deps target in makefile
TomasArrachea Sep 2, 2024
78a09a3
add codecov to ci
TomasArrachea Sep 2, 2024
35f43f9
remove lcov from ci
TomasArrachea Sep 2, 2024
f18e662
rename ci
TomasArrachea Sep 2, 2024
f5c7144
remove codecov action
TomasArrachea Sep 2, 2024
2414091
Merge branch 'main' into fireblock_tests_on_ci
TomasArrachea Sep 3, 2024
96a4ba5
add build step to CI
TomasArrachea Sep 3, 2024
1dfa9cd
add fireblocks-tests step to CI
TomasArrachea Sep 3, 2024
c1c3fe8
change read tests parameters from sandbox to testnet
Sep 9, 2024
1f530cf
contract_call
Sep 10, 2024
4b447e5
delete unused
Sep 10, 2024
149395d
add flag in assetid
Sep 10, 2024
07fde0a
clippy , lint
Sep 10, 2024
bd72aed
Merge branch 'main' into fireblock_tests_on_ci
TomasArrachea Sep 11, 2024
80ecce7
Merge branch 'main' into fireblock_tests_on_ci
TomasArrachea Sep 11, 2024
0a960de
update makefile fireblocks-tests target
TomasArrachea Sep 11, 2024
5cff592
fix tests CI
TomasArrachea Sep 11, 2024
1f70bfd
remove environment on fireblocks tests
TomasArrachea Sep 11, 2024
110e2de
add foundry installation
TomasArrachea Sep 11, 2024
c466b47
remove anvil for fireblocks tests
TomasArrachea Sep 11, 2024
2c57e74
update coverage target to include fireblocks tests
TomasArrachea Sep 13, 2024
2441d35
use printf to dump private key
TomasArrachea Sep 16, 2024
d9e71ea
add environment to CI
TomasArrachea Sep 16, 2024
31714b1
add debug step in CI
TomasArrachea Sep 16, 2024
6585c1b
remove testing environment
TomasArrachea Sep 16, 2024
2bb6c78
remove fireblocks tests CI
TomasArrachea Sep 17, 2024
b877e40
restore nightly rust installation on CI
TomasArrachea Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ jobs:
test:
name: Run Tests
runs-on: ubuntu-latest

env:
HOLESKY_WS_URL: ${{ secrets.HOLESKY_WS_URL }}
HOLESKY_HTTP_URL: ${{ secrets.HOLESKY_HTTP_URL }}
FIREBLOCKS_API_KEY: ${{ secrets.FIREBLOCKS_API_KEY }}
FIREBLOCKS_API_URL: ${{ secrets.FIREBLOCKS_API_URL }}

FIREBLOCKS_PRIVATE_KEY: ${{ secrets.FIREBLOCKS_PRIVATE_KEY }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -62,16 +61,16 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Create private key file
run: echo "${{ secrets.FIREBLOCKS_PRIVATE_KEY }}" > fireblocks_secret.key
run: printf "%b" "$FIREBLOCKS_PRIVATE_KEY" > fireblocks_secret.key

- name: Set environment variable for private key path
run: echo "FIREBLOCKS_PRIVATE_KEY_PATH=$(pwd)/fireblocks_secret.key" >> $GITHUB_ENV

- name: Install nightly Rust
run: rustup toolchain install nightly

- name: Install testing tools
uses: taiki-e/install-action@v2
with:
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pr:
coverage:
$(MAKE) start-anvil > /dev/null &
sleep 4 # needed to wait for anvil setup to finish
cargo llvm-cov --lcov --output-path lcov.info --ignore-filename-regex='fireblocks/' --workspace
cargo llvm-cov report --html --ignore-filename-regex='fireblocks/'
cargo llvm-cov --lcov --output-path lcov.info --workspace --features fireblock-tests
cargo llvm-cov report --html
docker stop anvil

deps:
Expand All @@ -33,8 +33,7 @@ deps:
fi

fireblocks-tests:
$(MAKE) start-anvil > /dev/null &
cargo test --workspace --features fireblock-tests
cargo test --package eigen-client-fireblocks --features fireblock-tests

lint:
cargo fmt --all -- --check \
Expand Down
165 changes: 89 additions & 76 deletions crates/chainio/clients/fireblocks/src/contract_call.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::client::AssetID;
use crate::client::Client;
use crate::status::Status;
use crate::error::FireBlockError;
use crate::transaction::TransactionRequest;
use crate::transaction::TransactionResponse;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TransactionOperation {
ContractCall,
Expand Down Expand Up @@ -45,74 +45,95 @@ impl std::fmt::Display for Account {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ExtraParams {
calldata: String,
pub enum ExtraParameters {
ContractCallData(String),
RawMessageData(RawMessageData),
}

impl std::fmt::Display for ExtraParams {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ExtraParams {{ contractCallData: {} }}", self.calldata)
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RawMessageData {
pub messages: Vec<UnsignedMessage>,
}

/// Contract Call Request
#[derive(Serialize, Deserialize, Debug)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ContractCallRequest {
/// Type of Operation
operation: TransactionOperation,
/// Tx id
external_tx_id: String,
/// [`AssetID`]
asset_id: AssetID,
/// Source [`Account`]
source: Account,
/// Destination [`Account`]
destination: Account,
/// Amount
amount: String,
/// Any extra parameters
extra_parameters: ExtraParams,
/// Replacement tx hash
replace_tx_by_hash: String,
pub struct UnsignedMessage {
pub content: String,
}

#[allow(unused)]
pub struct ContractCallResponse {
/// Response id
id: String,
/// Response [`Status`]
status: Status,
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TransferPeerPath {
#[serde(rename = "type")]
pub peer_type: Option<PeerType>,
pub id: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DestinationTransferPeerPath {
#[serde(rename = "type")]
pub peer_type: PeerType,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub one_time_address: Option<OneTimeAddress>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct OneTimeAddress {
pub address: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub tag: Option<String>,
}

#[allow(non_camel_case_types)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub enum PeerType {
VAULT_ACCOUNT,
EXCHANGE_ACCOUNT,
INTERNAL_WALLET,
EXTERNAL_WALLET,
ONE_TIME_ADDRESS,
NETWORK_CONNECTION,
FIAT_ACCOUNT,
COMPOUND,
END_USER_WALLET,
CONTRACT,
}

#[allow(async_fn_in_trait)]
pub trait ContractCall {
async fn contract_call(
&self,
transaction_request: TransactionRequest,
) -> Result<ContractCallRequest, String>;
) -> Result<TransactionResponse, FireBlockError>;
}

impl ContractCall for Client {
async fn contract_call(
&self,
mut transaction_request: TransactionRequest,
) -> Result<ContractCallRequest, String> {
let contract_call_request = transaction_request.get_contract_call();
transaction_request: TransactionRequest,
) -> Result<TransactionResponse, FireBlockError> {
let transaction_json =
serde_json::to_string(&transaction_request).map_err(FireBlockError::SerdeError)?;

// Call POST request
let contract_call_result = self
.post_request(&format!("/v1/transactions/{}", contract_call_request), None)
.post_request("/v1/transactions/", Some(&transaction_json.to_string()))
.await;
println!("contract call rquest: {:?}", contract_call_result);
match contract_call_result {
Ok(contract_call) => {
let contract_call_req: ContractCallRequest =
let contract_call_req: TransactionResponse =
serde_json::from_str(&contract_call).unwrap();
Ok(contract_call_req)
}
Err(e) => Err(e.to_string()),
Err(e) => Err(e),
}
}
}
Expand All @@ -123,6 +144,8 @@ mod tests {
#[cfg(feature = "fireblock-tests")]
use super::*;
#[cfg(feature = "fireblock-tests")]
use crate::client::AssetID;
#[cfg(feature = "fireblock-tests")]
use std::env;

#[tokio::test]
Expand All @@ -134,50 +157,40 @@ mod tests {
let api_url = env::var("FIREBLOCKS_API_URL").expect("FIREBLOCKS_API_URL not set");
let private_key =
std::fs::read_to_string(private_key_path).expect("Failed to read private key file");
// let tx_id = "10d377ac-0655-45c3-9d05-4fe0887787f3";

let client = Client::new(
api_key.to_string(),
private_key.to_string(),
api_url.clone(),
);
let external_tx_id = "";
let _account = Account {
type_field: "".to_string(),
id: "".to_string(),
};
let source = Account {
type_field: "".to_string(),
id: "".to_string(),
};
let destination = Account {
type_field: "".to_string(),
id: "".to_string(),
let source = TransferPeerPath {
peer_type: Some(PeerType::VAULT_ACCOUNT),
id: Some("13".to_string()),
};
let amount = "";
let extra_parameters = ExtraParams {
calldata: "".to_string(),
let destination = DestinationTransferPeerPath {
peer_type: PeerType::ONE_TIME_ADDRESS,
one_time_address: Some(OneTimeAddress {
address: "0x43506849D7C04F9138D1A2050bbF3A0c054402dd".to_string(),
tag: None,
}),
id: None,
};
let replace_tx_by_hash = "".to_string();
let gas_price = "".to_string();
let gas_limit = "".to_string();
let max_fee = "".to_string();
let priority_fee = "".to_string();
let fee_level = "".to_string();
let amount = "0";
let extra_params = ExtraParameters::ContractCallData("0x095ea7b3000000000000000000000000d09971d8ed6c6a5e57581e90d593ee5b94e348d4ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string());
let tx_request = TransactionRequest::new(
TransactionOperation::ContractCall.as_str().to_string(),
external_tx_id.to_string(),
AssetID::EthTest5,
TransactionOperation::ContractCall,
None,
AssetID::EthTest5.to_string(),
source,
destination,
Some(destination),
amount.to_string(),
extra_parameters,
replace_tx_by_hash,
gas_price,
gas_limit,
max_fee,
priority_fee,
fee_level,
Some(extra_params),
None,
None,
None,
None,
None,
None,
);

let _ = client.contract_call(tx_request).await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod tests {
let api_url = env::var("FIREBLOCKS_API_URL").expect("FIREBLOCKS_API_URL not set");
let private_key =
std::fs::read_to_string(private_key_path).expect("Failed to read private key file");
let vault_id = "1";
let vault_id = "13";
let asset_id: AssetID = AssetID::EthTest5;
let client = Client::new(
api_key.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crates/chainio/clients/fireblocks/src/get_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod tests {
let api_url = env::var("FIREBLOCKS_API_URL").expect("FIREBLOCKS_API_URL not set");
let private_key =
std::fs::read_to_string(private_key_path).expect("Failed to read private key file");
let tx_id = "10d377ac-0655-45c3-9d05-4fe0887787f3";
let tx_id = "4f182a65-07a0-46aa-b8aa-d047ab94f0aa";

let client = Client::new(
api_key.to_string(),
Expand Down
5 changes: 2 additions & 3 deletions crates/chainio/clients/fireblocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ impl FireblocksWallet {
.fireblocks_client
.get_transaction(tx_id.clone())
.await?;

match fireblocks_tx.status() {
Status::Completed => {
let provider = get_provider(&self.provider);
Expand Down Expand Up @@ -371,12 +370,12 @@ mod tests {
);
let mut fireblocks_wallet = FireblocksWallet::new(
client,
"https://ethereum-sepolia.rpc.subquery.network/public".to_string(),
"https://holesky.drpc.org".to_string(),
"vault-name".to_string(),
)
.await
.unwrap();
let tx_id = "10d377ac-0655-45c3-9d05-4fe0887787f3";
let tx_id = "39155aaa-cae7-45d8-824b-b74aef68edc0";
let _ = fireblocks_wallet
.get_transaction_receipt(tx_id.to_string())
.await
Expand Down
5 changes: 2 additions & 3 deletions crates/chainio/clients/fireblocks/src/list_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ mod tests {
let private_key_path =
env::var("FIREBLOCKS_PRIVATE_KEY_PATH").expect("FIREBLOCKS_PRIVATE_KEY_PATH not set");
let api_url = env::var("FIREBLOCKS_API_URL").expect("FIREBLOCKS_API_URL not set");
let private_key =
std::fs::read_to_string(private_key_path).expect("Failed to read private key file");

let private_key = std::fs::read_to_string(private_key_path.clone())
.expect("Failed to read private key file");
let client = Client::new(
api_key.to_string(),
private_key.to_string(),
Expand Down
10 changes: 5 additions & 5 deletions crates/chainio/clients/fireblocks/src/list_vault_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ struct Asset {
total: String,
balance: String,
available: String,
locked_amount: String,
pending: String,
frozen: String,
staked: String,
block_height: String,
locked_amount: Option<String>,
pending: Option<String>,
frozen: Option<String>,
staked: Option<String>,
block_height: Option<String>,
#[serde(default)]
block_hash: Option<String>,
}
Expand Down
Loading
Loading