diff --git a/Cargo.lock b/Cargo.lock index fb93fe5b..45846ce7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2529,15 +2529,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.13.0" @@ -4405,7 +4396,7 @@ checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15" dependencies = [ "bytes", "heck 0.5.0", - "itertools 0.12.1", + "itertools 0.13.0", "log", "multimap", "once_cell", @@ -4425,7 +4416,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" dependencies = [ "anyhow", - "itertools 0.12.1", + "itertools 0.13.0", "proc-macro2", "quote", "syn 2.0.87", diff --git a/ci/run-validator.sh b/ci/run-validator.sh index 7d6db003..e553894b 100755 --- a/ci/run-validator.sh +++ b/ci/run-validator.sh @@ -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 @@ -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 @@ -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 diff --git a/grpc/src/types/tx.rs b/grpc/src/types/tx.rs index 5ee829eb..03d30257 100644 --- a/grpc/src/types/tx.rs +++ b/grpc/src/types/tx.rs @@ -140,9 +140,19 @@ impl FromGrpcResponse for RawGetTxResponse { impl IntoGrpcParam for (RawTx, Vec, 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(), @@ -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) -> 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(), - } -} diff --git a/grpc/tests/tonic.rs b/grpc/tests/tonic.rs index 58dbb991..94581c2e 100644 --- a/grpc/tests/tonic.rs +++ b/grpc/tests/tonic.rs @@ -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() { @@ -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(); diff --git a/grpc/tests/utils.rs b/grpc/tests/utils.rs index 39bc795b..95fa0408 100644 --- a/grpc/tests/utils.rs +++ b/grpc/tests/utils.rs @@ -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 { @@ -51,11 +51,24 @@ pub async fn new_test_client() -> Result> { 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) }