Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbraun96 committed Dec 10, 2024
1 parent 2519490 commit 5b3e9d9
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 51 deletions.
6 changes: 0 additions & 6 deletions .envrc

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ build/

# Dependencies
node_modules/
dependencies/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "contracts/lib/tnt-core"]
path = contracts/lib/tnt-core
url = https://github.com/tangle-network/tnt-core
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ edition = "2021"

[package.metadata.blueprint]
manager = { Evm = "BlsBlueprint" }
master_revision = "Latest"

[dependencies]
gadget-sdk = { git = "https://github.com/tangle-network/gadget/", features = ["std"] }
gadget-sdk = { git = "https://github.com/tangle-network/gadget/", branch = "bls_debugging_dec10", features = ["std"] }
color-eyre = { version = "0.6", features = ["tracing-error", "color-spantrace"] }
tokio = { version = "1.40", default-features = false, features = ["full"] }
hex = { version = "0.4.3", default-features = false }
Expand All @@ -28,11 +29,11 @@ snowbridge-milagro-bls = "1.5.4"
gennaro-dkg = { version = "0.8.0", features = ["curve25519"]}

[build-dependencies]
blueprint-metadata = { git = "https://github.com/tangle-network/gadget/" }
blueprint-metadata = { git = "https://github.com/tangle-network/gadget/", branch = "bls_debugging_dec10" }

[dev-dependencies]
blueprint-test-utils = { git = "https://github.com/tangle-network/gadget/" }
cargo-tangle = { git = "https://github.com/tangle-network/gadget/" }
blueprint-test-utils = { git = "https://github.com/tangle-network/gadget/", branch = "bls_debugging_dec10" }
cargo-tangle = { git = "https://github.com/tangle-network/gadget/", branch = "bls_debugging_dec10" }
#alloy-primitives = "0.7.2"

[features]
Expand Down
Empty file removed blueprint.lock
Empty file.
1 change: 1 addition & 0 deletions contracts/lib/tnt-core
Submodule tnt-core added at df6d5d
1 change: 0 additions & 1 deletion contracts/soldeer.lock

This file was deleted.

63 changes: 61 additions & 2 deletions contracts/src/BlsBlueprint.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
// SPDX-License-Identifier: UNLICENSE
pragma solidity >=0.8.13;

import "tnt-core/BlueprintServiceManagerBase.sol";
import "contracts/lib/tnt-core/src/BlueprintServiceManagerBase.sol";

/**
* @title BlsBlueprint
* @dev This contract is an example of a service blueprint that provides a single service.
* @dev For all supported hooks, check the `BlueprintServiceManagerBase` contract.
*/
contract BlsBlueprint is BlueprintServiceManagerBase {}
contract BlsBlueprint is BlueprintServiceManagerBase {
/**
* @dev Hook for service operator registration. Called when a service operator
* attempts to register with the blueprint.
* @param operator The operator's details.
* @param _registrationInputs Inputs required for registration.
*/
function onRegister(bytes calldata operator, bytes calldata _registrationInputs)
public
payable
onlyFromRootChain
{
// Do something with the operator's details
}

/**
* @dev Hook for service instance requests. Called when a user requests a service
* instance from the blueprint.
* @param serviceId The ID of the requested service.
* @param operators The operators involved in the service.
* @param _requestInputs Inputs required for the service request.
*/
function onRequest(uint64 serviceId, bytes[] calldata operators, bytes calldata _requestInputs)
public
payable
onlyFromRootChain
{
// Do something with the service request
}

/**
* @dev Hook for handling job call results. Called when operators send the result
* of a job execution.
* @param serviceId The ID of the service related to the job.
* @param job The job identifier.
* @param _jobCallId The unique ID for the job call.
* @param participant The participant (operator) sending the result.
* @param _inputs Inputs used for the job execution.
* @param _outputs Outputs resulting from the job execution.
*/
function onJobResult(
uint64 serviceId,
uint8 job,
uint64 _jobCallId,
bytes calldata participant,
bytes calldata _inputs,
bytes calldata _outputs
) public payable virtual onlyFromRootChain {
// Do something with the job call result
}

/**
* @dev Converts a public key to an operator address.
* @param publicKey The public key to convert.
* @return operator address The operator address.
*/
function operatorAddressFromPublicKey(bytes calldata publicKey) internal pure returns (address operator) {
return address(uint160(uint256(keccak256(publicKey))));
}
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
packages = [];
# Environment variables
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.gmp pkgs.libclang pkgs.openssl.dev pkgs.stdenv.cc.cc ];
LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.gmp pkgs.libclang pkgs.openssl.dev ];
};
});
}
4 changes: 1 addition & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ out = "contracts/out"
script = "contracts/script"
cache_path = "contracts/cache"
broadcast = "contracts/broadcast"
libs = ["dependencies"]
libs = ["contracts/lib", "dependencies"]
auto_detect_remappings = true

[dependencies]
tnt-core = { version = "0.1.0", git = "https://github.com/tangle-network/tnt-core.git", rev = "dc71ca12f9b5d01b898adb2057c9b8846c90bda2" }
forge-std = "1.9.4"

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 0 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
forge-std/=dependencies/forge-std-1.9.4/src/
tnt-core/=dependencies/tnt-core-0.1.0/src/
12 changes: 0 additions & 12 deletions soldeer.lock

This file was deleted.

3 changes: 3 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct BlsContext {
pub network_backend: Arc<NetworkMultiplexer>,
pub store: Arc<LocalDatabase<BlsState>>,
pub identity: ecdsa::Pair,
#[call_id]
pub call_id: Option<u64>,
}

// Core context management implementation
Expand All @@ -53,6 +55,7 @@ impl BlsContext {
store,
identity,
config,
call_id: None,
network_backend: Arc::new(NetworkMultiplexer::new(gossip_handle)),
})
}
Expand Down
126 changes: 107 additions & 19 deletions tests/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,111 @@ mod e2e {
// when we pass the signing arguments, we can pass the associated keygen call id
static KEYGEN_CALL_ID: AtomicU64 = AtomicU64::new(0);

mpc_generate_keygen_and_signing_tests!(
"./",
N,
T,
KEYGEN_JOB_ID,
[InputValue::Uint16(T as u16)],
[],
SIGN_JOB_ID,
[
InputValue::Uint64(KEYGEN_CALL_ID.load(std::sync::atomic::Ordering::SeqCst)),
InputValue::List(BoundedVec(vec![
InputValue::Uint8(1),
InputValue::Uint8(2),
InputValue::Uint8(3),
]))
],
[],
KEYGEN_CALL_ID,
);
#[gadget_sdk::tokio::test(flavor = "multi_thread")]
async fn test_blueprint() {
blueprint_test_utils::setup_log();

let tmp_dir = blueprint_test_utils::tempfile::TempDir::new().unwrap();
let tmp_dir_path = tmp_dir.path().to_string_lossy().into_owned();

blueprint_test_utils::test_ext::new_test_ext_blueprint_manager::<N, 1, String, _, _>(
tmp_dir_path,
blueprint_test_utils::run_test_blueprint_manager,
)
.await
.execute_with_async(|client, handles, blueprint| async move {
let keypair = handles[0].sr25519_id().clone();
let service = &blueprint.services[0];

let service_id = service.id;
gadget_sdk::info!(
"Submitting KEYGEN job {} with service ID {service_id}", KEYGEN_JOB_ID
);

let job_args = vec![InputValue::Uint16(T as _)];

let job = submit_job(
client,
&keypair,
service_id,
Job::from(0),
job_args,
0,
)
.await
.expect("Failed to submit job");

let keygen_call_id = job.call_id;
KEYGEN_CALL_ID.store(keygen_call_id, std::sync::atomic::Ordering::Relaxed);

gadget_sdk::info!(
"Submitted KEYGEN job {} with service ID {service_id} has call id {keygen_call_id}", KEYGEN_JOB_ID,
);

let job_results = wait_for_completion_of_tangle_job(client, service_id, keygen_call_id, T)
.await
.expect("Failed to wait for job completion");

assert_eq!(job_results.service_id, service_id);
assert_eq!(job_results.call_id, keygen_call_id);

let expected_outputs = vec![];
if !expected_outputs.is_empty() {
assert_eq!(job_results.result.len(), expected_outputs.len(), "Number of keygen outputs doesn't match expected");

for (result, expected) in job_results.result.into_iter().zip(expected_outputs.into_iter()) {
assert_eq!(result, expected);
}
} else {
gadget_sdk::info!("No expected outputs specified, skipping keygen verification");
}

log::info!("Keygen job completed successfully! Moving on to signing ...");

// ~~~~~ Now, run a signing job ~~~~~
let service = &blueprint.services[0];

let service_id = service.id;
gadget_sdk::info!(
"Submitting SIGNING job {} with service ID {service_id}", SIGN_JOB_ID
);

// Pass the arguments
let job_args = vec![InputValue::Uint64(0), InputValue::List(BoundedVec(vec![InputValue::Uint8(1), InputValue::Uint8(2), InputValue::Uint8(3)]))];

let job = submit_job(
client,
&keypair,
service_id,
Job::from(1),
job_args,
1,
)
.await
.expect("Failed to submit job");

let signing_call_id = job.call_id;

gadget_sdk::info!(
"Submitted SIGNING job {} with service ID {service_id} has call id {signing_call_id}", SIGN_JOB_ID
);

let job_results =
wait_for_completion_of_tangle_job(client, service_id, signing_call_id, T)
.await
.expect("Failed to wait for job completion");

let expected_outputs = vec![];
if !expected_outputs.is_empty() {
assert_eq!(job_results.result.len(), expected_outputs.len(), "Number of signing outputs doesn't match expected");

for (result, expected) in job_results.result.into_iter().zip(expected_outputs.into_iter()) {
assert_eq!(result, expected);
}
} else {
gadget_sdk::info!("No expected outputs specified, skipping signing verification");
}
})
.await
}
}
6 changes: 6 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git submodule update --recursive --remote
git submodule foreach git pull origin HEAD
echo "Update submodules done"
cargo update
forge clean
forge build --force

0 comments on commit 5b3e9d9

Please sign in to comment.