Skip to content

Commit

Permalink
fix CI keygen
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Nov 20, 2024
1 parent a71eed3 commit 299ce05
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 47 deletions.
13 changes: 2 additions & 11 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions ci/run-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ provision_bridge_nodes() {
for node_idx in $(seq 0 "$last_node_idx"); do
local bridge_name="bridge-$node_idx"
local key_file="$CREDENTIALS_DIR/$bridge_name.key"
local plaintext_key_file="$CREDENTIALS_DIR/$bridge_name.plaintext-key"
local addr_file="$CREDENTIALS_DIR/$bridge_name.addr"

if [ ! -e "$key_file" ]; then
Expand All @@ -67,6 +68,8 @@ provision_bridge_nodes() {
celestia-appd keys add "$bridge_name" --keyring-backend "test"
# export it
echo "password" | celestia-appd keys export "$bridge_name" 2> "$key_file.lock"
# export also plaintext key for convenience in tests
echo y | celestia-appd keys export "$bridge_name" --unsafe --unarmored-hex 2> "${plaintext_key_file}"
# the `.lock` file and `mv` ensures that readers read file only after finished writing
mv "$key_file.lock" "$key_file"
# export associated address
Expand Down Expand Up @@ -105,10 +108,6 @@ provision_bridge_nodes() {
echo "Provisioning finished."
}

provision_grpc_account() {
#celestia-appd keys import
}

# Set up the validator for a private alone network.
# Based on
# https://github.com/celestiaorg/celestia-app/blob/main/scripts/single-node.sh
Expand Down
25 changes: 11 additions & 14 deletions grpc/src/types/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,19 @@ impl FromGrpcResponse<GetTxResponse> for RawGetTxResponse {
impl IntoGrpcParam<BroadcastTxRequest> for (RawTx, Vec<Blob>, BroadcastMode) {
fn into_parameter(self) -> BroadcastTxRequest {
let (tx, blobs, mode) = self;

// From https://github.com/celestiaorg/celestia-core/blob/v1.43.0-tm-v0.34.35/pkg/consts/consts.go#L19
const BLOB_TX_TYPE_ID: &str = "BLOB";

// empty blob list causes error response, but this is already checked when creating MsgPayForBlobs
debug_assert!(!blobs.is_empty());
let blob_tx = new_blob_tx(&tx, blobs);

let blobs = blobs.into_iter().map(RawBlob::from).collect();
let blob_tx = RawBlobTx {
tx: tx.encode_to_vec(),
blobs,
type_id: BLOB_TX_TYPE_ID.to_string(),
};
BroadcastTxRequest {
tx_bytes: blob_tx.encode_to_vec(),
mode: mode.into(),
Expand Down Expand Up @@ -234,16 +244,3 @@ pub fn prep_signed_tx(
signatures: vec![signature.to_bytes().to_vec()],
}
}


fn new_blob_tx(signed_tx: &RawTx, blobs: Vec<Blob>) -> RawBlobTx {
// From https://github.com/celestiaorg/celestia-core/blob/v1.43.0-tm-v0.34.35/pkg/consts/consts.go#L19
const BLOB_TX_TYPE_ID: &str = "BLOB";

let blobs = blobs.into_iter().map(RawBlob::from).collect();
RawBlobTx {
tx: signed_tx.encode_to_vec(),
blobs,
type_id: BLOB_TX_TYPE_ID.to_string(),
}
}
19 changes: 9 additions & 10 deletions grpc/tests/tonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
use celestia_grpc::types::auth::Account;
use celestia_grpc::types::tx::prep_signed_tx;
use celestia_proto::cosmos::tx::v1beta1::BroadcastMode;
use celestia_types::{blob::MsgPayForBlobs, nmt::Namespace, AppVersion, Blob};
use celestia_types::blob::MsgPayForBlobs;
use celestia_types::nmt::Namespace;
use celestia_types::{AppVersion, Blob};

pub mod utils;

use crate::utils::{load_account_key, new_test_client};
use crate::utils::{load_account, new_test_client};

const BRIDGE_0_DATA: &str = "../ci/credentials/bridge-0";

#[tokio::test]
async fn get_min_gas_price() {
Expand Down Expand Up @@ -68,16 +72,11 @@ async fn get_account() {
#[tokio::test]
async fn submit_blob() {
let mut client = new_test_client().await.unwrap();
let address = "celestia1rkfxnqt8wwu2vqgpa2ph84xa2ty0nseex4xqlc".to_string();
let private_key =
hex::decode("374b1d38f76c57fb6a1bb7bb840795239640441a37f506dc8de0d82b1ea9f690").unwrap();
let namespace = Namespace::new_v0(&[1, 2, 3]).unwrap();
let blob = Blob::new(namespace, "Hello, World!".into(), AppVersion::V1).unwrap();
let blobs = vec![blob];

let (address, keypair) = load_account(BRIDGE_0_DATA);
let namespace = Namespace::new_v0(&[1, 2, 3]).unwrap();
let blobs = vec![Blob::new(namespace, "Hello, World!".into(), AppVersion::V1).unwrap()];
let chain_id = "private".to_string();
let keypair = load_account_key(&private_key);

let account = client.get_account(address.clone()).await.unwrap();

let msg_pay_for_blobs = MsgPayForBlobs::new(&blobs, address).unwrap();
Expand Down
29 changes: 21 additions & 8 deletions grpc/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#![cfg(not(target_arch = "wasm32"))]

use std::env;
use std::{env, fs};

use anyhow::Result;
use celestia_tendermint::crypto::default::ecdsa_secp256k1::SigningKey;
use celestia_types::auth::AccountKeypair;
use tonic::metadata::{Ascii, MetadataValue};
use tonic::service::Interceptor;
use tonic::transport::Channel;
use tonic::{Request, Status};

use celestia_tendermint::crypto::default::ecdsa_secp256k1::SigningKey;
use celestia_types::auth::AccountKeypair;

use celestia_grpc::GrpcClient;

const CELESTIA_GRPC_URL: &str = "http://localhost:19090";
//const CELESTIA_GRPC_URL: &str = "https://rpc.celestia.pops.one:9090";

#[derive(Clone)]
pub struct TestAuthInterceptor {
Expand Down Expand Up @@ -51,11 +51,24 @@ pub async fn new_test_client() -> Result<GrpcClient<TestAuthInterceptor>> {
Ok(GrpcClient::new(grpc_channel, auth_interceptor))
}

pub fn load_account_key(key_bytes: &[u8]) -> AccountKeypair {
let signing_key = SigningKey::from_slice(key_bytes).unwrap();
pub fn load_account(path: &str) -> (String, AccountKeypair) {
let account_file = format!("{path}.addr");
let key_file = format!("{path}.plaintext-key");

AccountKeypair {
let account = fs::read_to_string(account_file).expect("file with account name to exists");
let hex_encoded_key = fs::read_to_string(key_file).expect("file with plaintext key to exists");
//let (_label, key_material) = SecretDocument::read_pem_file(key_file).expect("valid private key file");
//let key : EcPrivateKey = key_material.try_into().expect("valid key data");

let signing_key = SigningKey::from_slice(
&hex::decode(hex_encoded_key.trim()).expect("valid hex representation"),
)
.expect("valid key material");

let keypair = AccountKeypair {
verifying_key: *signing_key.verifying_key(),
signing_key,
}
};

(account.trim().to_string(), keypair)
}

0 comments on commit 299ce05

Please sign in to comment.