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

feat: RevealBody DR ID #213

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

67 changes: 53 additions & 14 deletions contract/src/msgs/data_requests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ fn reveal_result() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -270,6 +271,7 @@ fn reveal_result() {
let mut bob = test_info.new_executor("bob", Some(2));
bob.stake(&mut test_info, 1).unwrap();
let bob_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "20".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -306,6 +308,7 @@ fn reveal_result_with_proxies() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -343,6 +346,7 @@ fn reveal_result_with_proxies_not_valid_public_keys() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -374,6 +378,7 @@ fn reveal_result_reveal_body_missing_proxies() {

// alice commits a data result
let mut alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -404,6 +409,7 @@ fn cannot_reveal_if_commit_rf_not_met() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -431,6 +437,7 @@ fn cannot_reveal_if_user_did_not_commit() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -445,6 +452,7 @@ fn cannot_reveal_if_user_did_not_commit() {
let mut bob = test_info.new_executor("bob", Some(2));
bob.stake(&mut test_info, 1).unwrap();
let bob_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "20".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -475,6 +483,7 @@ fn cannot_double_reveal() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -489,6 +498,7 @@ fn cannot_double_reveal() {
let mut bob = test_info.new_executor("bob", Some(2));
bob.stake(&mut test_info, 1).unwrap();
let bob_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "20".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -521,6 +531,7 @@ fn reveal_must_match_commitment() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -532,6 +543,7 @@ fn reveal_must_match_commitment() {
&alice,
&dr_id,
RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "11".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -546,6 +558,7 @@ fn reveal_must_match_commitment() {
// bob also commits

let bob_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "20".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -576,6 +589,7 @@ fn post_data_result() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -608,6 +622,7 @@ fn post_data_results() {

// alice commits data result 1
let alice_reveal1 = RevealBody {
id: dr_id1.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -625,6 +640,7 @@ fn post_data_results() {

// alice commits data result 2
let alice_reveal2 = RevealBody {
id: dr_id2.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -665,6 +681,7 @@ fn cant_post_if_replication_factor_not_met() {

// alice commits a data result
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand All @@ -677,6 +694,7 @@ fn cant_post_if_replication_factor_not_met() {

// bob also commits
let bob_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "20".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -738,6 +756,7 @@ fn check_data_result_id() {

// reveal sample
let alice_reveal = RevealBody {
id: expected_result_id.to_owned(),
salt: "123".into(),
reveal: "10".hash().into(),
gas_used: 20u128.into(),
Expand Down Expand Up @@ -768,6 +787,7 @@ fn post_data_result_with_more_drs_in_the_pool() {

// Same commits & reveals for all drs
let alice_reveal = RevealBody {
id: dr_id1.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down Expand Up @@ -852,17 +872,18 @@ fn get_data_requests_by_status_with_more_drs_in_pool() {

let mut alice = test_info.new_executor("alice", Some(2));
alice.stake(&mut test_info, 1).unwrap();
let alice_reveal = RevealBody {
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
exit_code: 0,
proxy_public_keys: vec![],
};

for i in 0..25 {
let dr = test_helpers::calculate_dr_id_and_args(i, 1);
let dr_id = test_info.post_data_request(&alice, dr, vec![], vec![], 1).unwrap();
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
exit_code: 0,
proxy_public_keys: vec![],
};

if i < 15 {
test_info
Expand Down Expand Up @@ -901,19 +922,20 @@ fn get_data_requests_by_status_with_many_more_drs_in_pool() {

let mut alice = test_info.new_executor("alice", Some(2));
alice.stake(&mut test_info, 1).unwrap();
let alice_reveal = RevealBody {
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
exit_code: 0,
proxy_public_keys: vec![],
};

for i in 0..100 {
let dr = test_helpers::calculate_dr_id_and_args(i, 1);
let dr_id = test_info
.post_data_request(&alice, dr.clone(), vec![], vec![], 1)
.unwrap();
let alice_reveal = RevealBody {
id: dr_id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
exit_code: 0,
proxy_public_keys: vec![],
};

if i % 2 == 0 {
test_info
Expand Down Expand Up @@ -951,6 +973,15 @@ fn get_data_requests_by_status_with_many_more_drs_in_pool() {
.enumerate()
{
if i % 4 == 0 {
let alice_reveal = RevealBody {
id: request.id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
exit_code: 0,
proxy_public_keys: vec![],
};

test_info
.reveal_result(&alice, &request.id, alice_reveal.clone())
.unwrap();
Expand Down Expand Up @@ -985,6 +1016,14 @@ fn get_data_requests_by_status_with_many_more_drs_in_pool() {
.enumerate()
{
if i % 8 == 0 {
let alice_reveal = RevealBody {
id: request.id.clone(),
salt: alice.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
exit_code: 0,
proxy_public_keys: vec![],
};
let dr_info = test_info.get_data_request(&request.id).unwrap();
let result = test_helpers::construct_result(dr_info.clone(), alice_reveal.clone(), 0);
test_info.post_data_result(request.id.to_string(), result, 0).unwrap();
Expand Down
1 change: 1 addition & 0 deletions contract/src/msgs/staking/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fn executor_not_eligible_if_dr_resolved() {
.unwrap();

let reveal = RevealBody {
id: dr_id.clone(),
salt: anyone.salt(),
reveal: "10".hash().into(),
gas_used: 0u128.into(),
Expand Down
14 changes: 12 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ fn wasm_opt(sh: &Shell) -> Result<()> {
}

fn create_data_request(
id: [u8; 32],
dr_binary_id: [u8; 32],
tally_binary_id: [u8; 32],
replication_factor: u16,
tally_inputs: Vec<u8>,
reveals: HashMap<String, RevealBody>,
) -> DataRequest {
let id: [u8; 32] = rand::random();
DataRequest {
version: semver::Version {
major: 1,
Expand Down Expand Up @@ -120,10 +120,13 @@ fn tally_test_fixture(n: usize) -> Vec<DataRequest> {
.collect();
let replication_factor = rand::thread_rng().gen_range(1..=3);

let dr_id: [u8; 32] = rand::random();
let hex_dr_id = dr_id.to_hex();
let salt: [u8; 32] = rand::random();
let reveals = (0..replication_factor)
.map(|_| {
let reveal = RevealBody {
id: hex_dr_id.clone(),
salt: salt.to_hex(),
exit_code: 0,
gas_used: 10u128.into(),
Expand All @@ -141,7 +144,14 @@ fn tally_test_fixture(n: usize) -> Vec<DataRequest> {
})
.collect();

create_data_request(dr_binary_id, tally_binary_id, replication_factor, inputs, reveals)
create_data_request(
dr_id,
dr_binary_id,
tally_binary_id,
replication_factor,
inputs,
reveals,
)
})
.collect()
}
Expand Down