diff --git a/deployment-guide.md b/deployment-guide.md index 921cec57..4dd94550 100644 --- a/deployment-guide.md +++ b/deployment-guide.md @@ -55,7 +55,7 @@ It also provides an SDK in Rust that can be used to interact with it. You can ch 1. Send a callback request directly to the Relay by running: ```bash - cargo run --example offchain_request "$APP_ADDRESS" 10 + BONSAI_API_KEY="YOUR_API_KEY_OR_EMPTY_IF_DEV_MODE" cargo run --example offchain_request "$APP_ADDRESS" 10 ``` 2. Check the relayed result: @@ -156,7 +156,7 @@ You now have a deployment on a testnet that you can interact with sending either 1. Send a callback request directly to the Relay by running: ```bash - cargo run --example offchain_request "$APP_ADDRESS" 10 + BONSAI_API_KEY="YOUR_API_KEY_OR_EMPTY_IF_DEV_MODE" cargo run --example offchain_request "$APP_ADDRESS" 10 ``` 2. Check the relayed result: diff --git a/relay/examples/offchain_request.rs b/relay/examples/offchain_request.rs index 10f0b921..f5ef6773 100644 --- a/relay/examples/offchain_request.rs +++ b/relay/examples/offchain_request.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::env; + use alloy_primitives::U256; use alloy_sol_types::SolValue; use anyhow::Context; @@ -38,18 +40,27 @@ struct Args { bonsai_relay_api_url: String, /// Bonsai API key. Used by the relay to send requests to the Bonsai proving - /// service. Defaults to empty, providing no authentication. - #[arg(long, env, default_value = "")] - bonsai_api_key: String, + /// service. Can be set to an empty string when DEV_MODE is enabled. + #[arg(long, env)] + bonsai_api_key: Option, } #[tokio::main] async fn main() -> anyhow::Result<()> { let args = Args::parse(); + // check for bonsai_api_key + if args.bonsai_api_key.is_none() && env::var("BONSAI_API_KEY").is_err() { + eprintln!( + "Error: the following required arguments were not provided: \ + \n'BONSAI_API_KEY' must be set either as an argument or as an environment variable. \ + \nIf `DEV_MODE` is enabled, you can use an empty string." + ); + std::process::exit(1); + } // initialize a relay client let relay_client = Client::from_parts( - args.bonsai_relay_api_url.clone(), // Set BONSAI_API_URL or replace this line. - args.bonsai_api_key.clone(), // Set BONSAI_API_KEY or replace this line. + args.bonsai_relay_api_url.clone(), + args.bonsai_api_key.unwrap(), ) .context("Failed to initialize the relay client")?; diff --git a/tests/BonsaiStarter.t.sol b/tests/BonsaiStarter.t.sol index 07ce5468..6e14650c 100644 --- a/tests/BonsaiStarter.t.sol +++ b/tests/BonsaiStarter.t.sol @@ -27,10 +27,7 @@ contract BonsaiStarterTest is BonsaiTest { function testOffChainMock() public { bytes32 imageId = queryImageId("FIBONACCI"); // Deploy a new starter instance - BonsaiStarter starter = new BonsaiStarter( - IBonsaiRelay(bonsaiRelay), - imageId - ); + BonsaiStarter starter = new BonsaiStarter(IBonsaiRelay(bonsaiRelay), imageId); // Anticipate a callback invocation on the starter contract vm.expectCall(address(starter), abi.encodeWithSelector(BonsaiStarter.storeResult.selector)); @@ -48,10 +45,7 @@ contract BonsaiStarterTest is BonsaiTest { // Test the BonsaiStarter contract by mocking an on-chain callback request function testOnChainMock() public { // Deploy a new starter instance - BonsaiStarter starter = new BonsaiStarter( - IBonsaiRelay(bonsaiRelay), - queryImageId("FIBONACCI") - ); + BonsaiStarter starter = new BonsaiStarter(IBonsaiRelay(bonsaiRelay), queryImageId("FIBONACCI")); // Anticipate an on-chain callback request to the relay vm.expectCall(address(bonsaiRelay), abi.encodeWithSelector(IBonsaiRelay.requestCallback.selector)); diff --git a/tests/BonsaiStarterLowLevel.t.sol b/tests/BonsaiStarterLowLevel.t.sol index c7f21075..32dcb41b 100644 --- a/tests/BonsaiStarterLowLevel.t.sol +++ b/tests/BonsaiStarterLowLevel.t.sol @@ -25,9 +25,7 @@ contract BonsaiStarterLowLevelTest is BonsaiTest { function testMockLowLevelCall() public { // Deploy a new starter instance - BonsaiStarterLowLevel starter = new BonsaiStarterLowLevel( - IBonsaiRelay(bonsaiRelay), - queryImageId('FIBONACCI')); + BonsaiStarterLowLevel starter = new BonsaiStarterLowLevel(IBonsaiRelay(bonsaiRelay), queryImageId("FIBONACCI")); // Anticipate a callback request to the relay vm.expectCall(address(bonsaiRelay), abi.encodeWithSelector(IBonsaiRelay.requestCallback.selector));