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

[solana] Solana tests 2 #1255

Merged
merged 16 commits into from
Jan 30, 2024
3 changes: 2 additions & 1 deletion pythnet/pythnet_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["lib"]
name = "pythnet_sdk"

[features]
test-utils = ["dep:wormhole-sdk", "dep:serde_wormhole"]
test-utils = ["dep:wormhole-sdk", "dep:serde_wormhole", "dep:libsecp256k1"]

[dependencies]
bincode = "1.3.1"
Expand All @@ -28,6 +28,7 @@ slow_primes = "0.1.14"
thiserror = "1.0.40"
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", optional = true, tag="rust-sdk-2024-01-25"}
wormhole-sdk = { git = "https://github.com/wormhole-foundation/wormhole", optional = true, tag="rust-sdk-2024-01-25"}
libsecp256k1 = {version ="0.7.1", optional = true}

[dev-dependencies]
base64 = "0.21.0"
Expand Down
62 changes: 58 additions & 4 deletions pythnet/pythnet_sdk/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ use {
},
},
byteorder::BigEndian,
libsecp256k1::{
Message as libsecp256k1Message,
RecoveryId,
SecretKey,
Signature,
},
serde_wormhole::RawMessage,
wormhole_sdk::{
vaa::{
digest,
Body,
Header,
},
Address,
Chain,
Vaa,
Expand Down Expand Up @@ -67,6 +78,18 @@ pub const DEFAULT_VALID_TIME_PERIOD: u64 = 180;

const DEFAULT_SEQUENCE: u64 = 2;

const NUM_GUARDIANS: u8 = 19;
const NUM_SIGNATURES: usize = 13;

pub fn create_dummy_guardians() -> Vec<SecretKey> {
let mut result: Vec<SecretKey> = vec![];
for i in 0..NUM_GUARDIANS {
let mut secret_key_bytes = [0u8; 32];
secret_key_bytes[0] = i + 1;
result.push(SecretKey::parse(&secret_key_bytes).unwrap());
}
result
}
guibescos marked this conversation as resolved.
Show resolved Hide resolved

pub fn create_dummy_price_feed_message(value: i64) -> Message {
let mut dummy_id = [0; 32];
Expand Down Expand Up @@ -155,12 +178,43 @@ pub fn create_vaa_from_payload(
emitter_chain: Chain,
sequence: u64,
) -> Vaa<Box<RawMessage>> {
let vaa: Vaa<Box<RawMessage>> = Vaa {
emitter_chain: emitter_chain,
emitter_address: emitter_address,
let guardians = create_dummy_guardians();

let body: Body<Box<RawMessage>> = Body {
emitter_chain,
emitter_address,
sequence,
payload: <Box<RawMessage>>::from(payload.to_vec()),
..Default::default()
};
vaa

let digest = libsecp256k1Message::parse_slice(&body.digest().unwrap().secp256k_hash).unwrap();

let signatures: Vec<(Signature, RecoveryId)> = guardians[0..NUM_SIGNATURES]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the number of signatures should be an argument to the function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also do you want it to be the case that it's always the first N guardians who signed? are there possible tests where you want a random subset of guardians or something?

I would think about the range of configurability you need downstream and then try to build that in to the test methods here.

Another similar question would be whether you need the ability to define & work with different guardian sets in the tests. In that case, you may want to make the signing guardian keys an argument to this function.

Copy link
Contributor Author

@guibescos guibescos Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so I switched to having random subsets of guardians. I don't think I need more configurability for now.

.iter()
.map(|x| libsecp256k1::sign(&digest, &x))
.collect();
let wormhole_signatures: Vec<wormhole_sdk::vaa::Signature> = signatures
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding actual signatures to the common sdk

.iter()
.enumerate()
.map(|(i, (x, y))| {
let mut signature = [0u8; 65];
signature[..64].copy_from_slice(&x.serialize());
signature[64] = y.serialize();
wormhole_sdk::vaa::Signature {
index: i as u8,
signature,
}
})
.collect();


let header = Header {
version: 1,
signatures: wormhole_signatures,
..Default::default()
};


(header, body).into()
}
115 changes: 114 additions & 1 deletion target_chains/cosmwasm/Cargo.lock

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

70 changes: 70 additions & 0 deletions target_chains/near/receiver/Cargo.lock

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

3 changes: 3 additions & 0 deletions target_chains/solana/Cargo.lock

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

Loading
Loading