-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
263 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
bitcoinInfo: | ||
rpcUsername: testuser | ||
rpcPassword: lq6zequb-gYTdF2_ZEUtr8ywTXzLYtknzWU4nV8uVoo= | ||
rpcPort: 18443 | ||
rpcHost: localhost | ||
wallet: alice | ||
storageDirPath: './dlc_sample_alice' | ||
networkConfiguration: | ||
peerListeningPort: 9000 | ||
network: regtest | ||
oracleConfig: | ||
host: 'http://localhost:8080/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
bitcoinInfo: | ||
rpcUsername: testuser | ||
rpcPassword: lq6zequb-gYTdF2_ZEUtr8ywTXzLYtknzWU4nV8uVoo= | ||
rpcPort: 18443 | ||
rpcHost: localhost | ||
wallet: bob | ||
storageDirPath: './dlc_sample_bob' | ||
networkConfiguration: | ||
peerListeningPort: 9001 | ||
network: regtest | ||
oracleConfig: | ||
host: 'http://localhost:8080/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ | ||
"offerCollateral": 100000000, | ||
"acceptCollateral": 100000000, | ||
"feeRate": 2, | ||
"contractInfos": [ | ||
{ | ||
"contractDescriptor": { | ||
"numerical": { | ||
"payoutFunction": { | ||
"payoutFunctionPieces": [ | ||
{ | ||
"polynomialPayoutCurvePiece": { | ||
"payoutPoints": [ | ||
{ | ||
"eventOutcome": 0, | ||
"outcomePayout": 0, | ||
"extraPrecision": 0 | ||
}, | ||
{ | ||
"eventOutcome": 50000, | ||
"outcomePayout": 0, | ||
"extraPrecision": 0 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"polynomialPayoutCurvePiece": { | ||
"payoutPoints": [ | ||
{ | ||
"eventOutcome": 50000, | ||
"outcomePayout": 0, | ||
"extraPrecision": 0 | ||
}, | ||
{ | ||
"eventOutcome": 60000, | ||
"outcomePayout": 200000000, | ||
"extraPrecision": 0 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"polynomialPayoutCurvePiece": { | ||
"payoutPoints": [ | ||
{ | ||
"eventOutcome": 60000, | ||
"outcomePayout": 200000000, | ||
"extraPrecision": 0 | ||
}, | ||
{ | ||
"eventOutcome": 1048575, | ||
"outcomePayout": 200000000, | ||
"extraPrecision": 0 | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"roundingIntervals": { | ||
"intervals": [ | ||
{ | ||
"beginInterval": 0, | ||
"roundingMod": 1 | ||
} | ||
] | ||
}, | ||
"differenceParams": null, | ||
"oracleNumericInfos": { | ||
"base": 2, | ||
"nbDigits": [ | ||
20 | ||
] | ||
} | ||
} | ||
}, | ||
"oracles": { | ||
"publicKeys": [ | ||
"0d829c1cc556aa59060df5a9543c5357199ace5db9bcd5a8ddd6ee2fc7b6d174" | ||
], | ||
"eventId": "btcusd1707116236", | ||
"threshold": 1 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use dlc_manager::contract::contract_input::ContractInput; | ||
use rexpect::session::spawn_command; | ||
use std::{ | ||
ops::Add, | ||
process::Command, | ||
time::{Duration, UNIX_EPOCH}, | ||
}; | ||
|
||
fn update_contract_offer_time() { | ||
let mut contract_offer: ContractInput = serde_json::from_str(include_str!( | ||
"../tests/contracts/numerical_contract_input.json" | ||
)) | ||
.unwrap(); | ||
let maturity = std::time::SystemTime::now().add(Duration::from_secs(60 * 3)); | ||
let maturity_epoch = maturity.duration_since(UNIX_EPOCH).unwrap().as_secs(); | ||
contract_offer.contract_infos[0].oracles.event_id = format!("btcusd{maturity_epoch}"); | ||
let updated = serde_json::to_string_pretty(&contract_offer).unwrap(); | ||
std::fs::write("./tests/contracts/numerical_contract_input.json", &updated).unwrap(); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn sample_offer_accept_test() { | ||
update_contract_offer_time(); | ||
bitcoin_test_utils::rpc_helpers::init_clients(); | ||
let bin_path = assert_cmd::cargo::cargo_bin("sample"); | ||
let mut cmd = Command::new(&bin_path); | ||
cmd.arg("./tests/configurations/alice.yml"); | ||
|
||
let mut alice_process = spawn_command(cmd, Some(30000)).unwrap(); | ||
|
||
let (_, alice_node_id) = alice_process.exp_regex("[0-9a-f]{66}").unwrap(); | ||
|
||
let mut cmd = Command::new(bin_path); | ||
cmd.arg("./tests/configurations/bob.yml"); | ||
|
||
let mut bob_process = spawn_command(cmd, Some(30000)).unwrap(); | ||
bob_process.exp_regex("[0-9a-f]{66}").unwrap(); | ||
|
||
alice_process.exp_string(">").unwrap(); | ||
bob_process.exp_string(">").unwrap(); | ||
|
||
bob_process | ||
.send_line(&format!("offercontract {alice_node_id}@127.0.0.1:9000 ./tests/contracts/numerical_contract_input.json")) | ||
.unwrap(); | ||
bob_process.exp_regex("SUCCESS").unwrap(); | ||
bob_process.exp_string(">").unwrap(); | ||
alice_process.send_line("").unwrap(); | ||
alice_process.exp_string(">").unwrap(); | ||
alice_process.send_line("listoffers").unwrap(); | ||
|
||
let (_, mut contract_id) = alice_process.exp_regex("[0-9a-f]{64}\"").unwrap(); | ||
contract_id.pop(); | ||
|
||
alice_process.exp_string(">").unwrap(); | ||
alice_process | ||
.send_line(&format!("acceptoffer {contract_id}")) | ||
.unwrap(); | ||
alice_process.exp_string(">").unwrap(); | ||
|
||
// Give time for accept message to be delivered. | ||
std::thread::sleep(std::time::Duration::from_secs(1)); | ||
bob_process.send_line("").unwrap(); | ||
bob_process.exp_string("Sending").unwrap(); | ||
|
||
// Give time for sign message to be delivered. | ||
std::thread::sleep(std::time::Duration::from_secs(1)); | ||
alice_process.send_line("").unwrap(); | ||
alice_process.exp_string("Processing").unwrap(); | ||
alice_process.exp_string(">").unwrap(); | ||
alice_process.send_line("listcontracts").unwrap(); | ||
|
||
// At that point the contract should be in signed state. | ||
alice_process.exp_string("Signed").unwrap(); | ||
} |