-
Notifications
You must be signed in to change notification settings - Fork 75
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
Feat: add stellar ledger as signer #1627
base: main
Are you sure you want to change the base?
Changes from 19 commits
2083a7a
aee08f8
b02ffc2
a67f587
70e58b0
0369e05
91a5f2b
6a4986e
efd2948
518e591
1fa59d8
a0055a9
5755990
0aaf7c5
8799cd0
98b0100
37f302d
09eff2f
4680b96
567e2ab
dd1d079
efa4f3a
7537edb
2d22fb4
a1c654b
a04ab20
4291ad1
6143b84
9a13673
a210205
cb3f499
75df1cb
c9456fe
f2d8fe7
6212d31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ test_snapshots | |
.idea | ||
local.sh | ||
.stellar | ||
.zed |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ mod snapshot; | |
mod tx; | ||
mod util; | ||
mod wrap; | ||
|
||
#[cfg(feature = "emulator-tests")] | ||
mod emulator; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use stellar_ledger::{Blob, Error}; | ||
|
||
use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE}; | ||
use std::sync::Arc; | ||
|
||
use soroban_cli::xdr::{ | ||
self, Memo, MuxedAccount, Operation, OperationBody, PaymentOp, Preconditions, SequenceNumber, | ||
Transaction, TransactionExt, Uint256, | ||
}; | ||
|
||
use stellar_ledger::emulator_test_support::*; | ||
|
||
use test_case::test_case; | ||
|
||
use crate::integration::util::{deploy_contract, DeployKind, HELLO_WORLD}; | ||
|
||
// #[test_case("nanos"; "when the device is NanoS")] | ||
#[test_case("nanox"; "when the device is NanoX")] | ||
// #[test_case("nanosp"; "when the device is NanoS Plus")] | ||
#[tokio::test] | ||
async fn test_get_public_key(ledger_device_model: &str) { | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let sandbox = Arc::new(TestEnv::new()); | ||
let container = TestEnv::speculos_container(ledger_device_model).await; | ||
let host_port = container.get_host_port_ipv4(9998).await.unwrap(); | ||
let ui_host_port = container.get_host_port_ipv4(5000).await.unwrap(); | ||
|
||
let ledger = ledger(host_port).await; | ||
|
||
let key = ledger.get_public_key(&0.into()).await.unwrap(); | ||
let account = &key.to_string(); | ||
sandbox.fund_account(account); | ||
sandbox | ||
.new_assert_cmd("contract") | ||
.arg("install") | ||
.args([ | ||
"--wasm", | ||
HELLO_WORLD.path().as_os_str().to_str().unwrap(), | ||
"--source", | ||
account, | ||
]) | ||
.assert() | ||
.success(); | ||
|
||
let tx_simulated = | ||
deploy_contract(&sandbox, HELLO_WORLD, DeployKind::SimOnly, Some(account)).await; | ||
dbg!("{tx_simulated}"); | ||
let key = ledger.get_public_key(&0.into()).await.unwrap(); | ||
println!("{key}"); | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let sign = tokio::task::spawn_blocking({ | ||
let sandbox = Arc::clone(&sandbox); | ||
|
||
move || { | ||
sandbox | ||
.new_assert_cmd("tx") | ||
.arg("sign") | ||
.arg("--sign-with-ledger") | ||
.write_stdin(tx_simulated.as_bytes()) | ||
.env("SPECULOS_PORT", host_port.to_string()) | ||
.env("RUST_LOGS", "trace") | ||
.assert() | ||
.success() | ||
.stdout_as_str() | ||
} | ||
}); | ||
let approve = tokio::task::spawn(approve_tx_hash_signature( | ||
ui_host_port, | ||
ledger_device_model.to_string(), | ||
)); | ||
|
||
let response = sign.await.unwrap(); | ||
approve.await.unwrap(); | ||
|
||
dbg!("{tx_signed}"); | ||
|
||
sandbox | ||
.clone() | ||
.new_assert_cmd("tx") | ||
.arg("send") | ||
.write_stdin(response.as_bytes()) | ||
.assert() | ||
.success() | ||
.stdout(predicates::str::contains("SUCCESS")); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub mod http_transport; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant to add a |
||
#[cfg(feature = "emulator-tests")] | ||
pub mod speculos; | ||
#[cfg(feature = "emulator-tests")] | ||
pub mod util; | ||
#[cfg(feature = "emulator-tests")] | ||
pub use util::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can uncomment these other device model test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was running into issues around the server locally. Since all the accounts share the same seed phrase it was acting as one account. I also tried updating the testcase to add an hd-path, but it was causes issues. So I just wanted one to work on CI and then was going to return to it.