Update Solution to string, and align tests.

This commit is contained in:
FiveMovesAhead 2025-10-06 11:04:10 +01:00
parent 2149bf6790
commit 96bdf6fb0a
4 changed files with 14 additions and 46 deletions

View File

@ -104,7 +104,7 @@ class OutputData(FromDict):
nonce: int
runtime_signature: int
fuel_consumed: int
solution: dict
solution: str
cpu_arch: str
def calc_solution_signature(self) -> int:

View File

@ -10,20 +10,16 @@ from common.structs import BenchmarkSettings, OutputData
class TestData(unittest.TestCase):
def test_calc_solution_signature(self):
solution = {
"data_x": 42,
"data_y": "test"
}
output_data = OutputData(
nonce=123,
runtime_signature=456,
fuel_consumed=789,
solution=solution
solution="test",
cpu_arch="AMD64"
)
# Assert same as Rust version: tig-structs/tests/core.rs
self.assertEqual(output_data.calc_solution_signature(), 11549591319018095145)
self.assertEqual(output_data.calc_solution_signature(), 11204800550749450632)
def test_calc_seed(self):
settings = BenchmarkSettings(
@ -45,24 +41,20 @@ class TestData(unittest.TestCase):
self.assertEqual(settings.calc_seed(rand_hash, nonce), expected)
def test_outputdata_to_merklehash(self):
solution = {
"data_x": 42,
"data_y": "test"
}
output_data = OutputData(
nonce=123,
runtime_signature=456,
fuel_consumed=789,
solution=solution
solution="test",
cpu_arch="AMD64"
)
merkle_hash = output_data.to_merkle_hash()
# Assert same as Rust version: tig-structs/tests/core.rs
expected = MerkleHash(bytes([
207, 29, 184, 163, 158, 22, 137, 73, 72, 58, 24, 246, 67, 9, 44, 20,
32, 22, 86, 206, 191, 5, 52, 241, 41, 113, 198, 85, 11, 53, 190, 57
79, 126, 186, 90, 12, 111, 100, 8, 120, 150, 225, 176, 200, 201, 125, 150, 58, 122,
214, 216, 68, 6, 125, 247, 248, 4, 165, 185, 157, 44, 13, 151
]))
self.assertEqual(merkle_hash, expected)

View File

@ -303,12 +303,6 @@ serializable_struct_with_getters! {
}
// Code child structs
serializable_struct_with_getters! {
SourceCode {
rust: String,
cuda: Option<String>,
}
}
serializable_struct_with_getters! {
CodeDetails {
name: String,
@ -452,13 +446,12 @@ pub enum CPUArchitecture {
AMD64,
ARM64,
}
pub type Solution = Map<String, Value>;
serializable_struct_with_getters! {
OutputData {
nonce: u64,
runtime_signature: u64,
fuel_consumed: u64,
solution: Solution,
solution: String,
cpu_arch: CPUArchitecture,
}
}

View File

@ -1,27 +1,18 @@
use serde_json::json;
use tig_structs::core::{BenchmarkSettings, CPUArchitecture, OutputData};
use tig_utils::MerkleHash;
#[test]
fn test_calc_solution_signature() {
let solution = json!({
"data_x": 42,
"data_y": "test"
})
.as_object()
.unwrap()
.clone();
let output_data = OutputData {
nonce: 123,
runtime_signature: 456,
fuel_consumed: 789,
solution: solution.clone(),
solution: "test".to_string(),
cpu_arch: CPUArchitecture::AMD64,
};
// Assert same as Python version: tig-benchmarker/tests/core.rs
assert_eq!(output_data.calc_solution_signature(), 11549591319018095145);
assert_eq!(output_data.calc_solution_signature(), 11204800550749450632);
}
#[test]
@ -49,19 +40,11 @@ fn test_calc_seed() {
#[test]
fn test_outputdata_to_merklehash() {
let solution = json!({
"data_x": 42,
"data_y": "test"
})
.as_object()
.unwrap()
.clone();
let output_data = OutputData {
nonce: 123,
runtime_signature: 456,
fuel_consumed: 789,
solution: solution.clone(),
solution: "test".to_string(),
cpu_arch: CPUArchitecture::AMD64,
};
@ -71,8 +54,8 @@ fn test_outputdata_to_merklehash() {
assert_eq!(
merkle_hash,
MerkleHash([
207, 29, 184, 163, 158, 22, 137, 73, 72, 58, 24, 246, 67, 9, 44, 20, 32, 22, 86, 206,
191, 5, 52, 241, 41, 113, 198, 85, 11, 53, 190, 57
79, 126, 186, 90, 12, 111, 100, 8, 120, 150, 225, 176, 200, 201, 125, 150, 58, 122,
214, 216, 68, 6, 125, 247, 248, 4, 165, 185, 157, 44, 13, 151
])
);
}