diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index abc7082..ad0878e 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: ^1.21 + go-version: "1.22" id: go - name: Check out code into the Go module directory @@ -54,7 +54,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: ^1.22 + go-version: "1.22" id: go - name: Check out code into the Go module directory and submodules diff --git a/examples/mevm-confidential-store/confidential-store.sol b/examples/mevm-confidential-store/confidential-store.sol index f43441f..102483c 100644 --- a/examples/mevm-confidential-store/confidential-store.sol +++ b/examples/mevm-confidential-store/confidential-store.sol @@ -6,11 +6,11 @@ import "suave-std/suavelib/Suave.sol"; contract ConfidentialStore { function callback() external {} - function example() external returns (bytes memory) { + function example(string memory namespace) external returns (bytes memory) { address[] memory allowedList = new address[](1); allowedList[0] = address(this); - Suave.DataRecord memory dataRecord = Suave.newDataRecord(10, allowedList, allowedList, "namespace"); + Suave.DataRecord memory dataRecord = Suave.newDataRecord(10, allowedList, allowedList, namespace); Suave.confidentialStore(dataRecord.id, "key1", abi.encode(1)); Suave.confidentialStore(dataRecord.id, "key2", abi.encode(2)); @@ -18,7 +18,29 @@ contract ConfidentialStore { bytes memory value = Suave.confidentialRetrieve(dataRecord.id, "key1"); require(keccak256(value) == keccak256(abi.encode(1))); - Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, "namespace"); + Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, namespace); + require(allShareMatchBids.length == 1); + + return abi.encodeWithSelector(this.callback.selector); + } + + function example2(string memory namespace) external returns (bytes memory) { + // Add a new entry for the confidential store combination (10, namespace) + address[] memory allowedList = new address[](1); + allowedList[0] = address(this); + + Suave.newDataRecord(10, allowedList, allowedList, namespace); + + Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, namespace); + require(allShareMatchBids.length == 2); + + return abi.encodeWithSelector(this.callback.selector); + } + + function query(string memory namespace) external returns (bytes memory) { + Suave.DataRecord[] memory allShareMatchBids = Suave.fetchDataRecords(10, namespace); + require(allShareMatchBids.length == 2); + return abi.encodeWithSelector(this.callback.selector); } } diff --git a/examples/mevm-confidential-store/main.go b/examples/mevm-confidential-store/main.go index 85cd669..4ab4a40 100644 --- a/examples/mevm-confidential-store/main.go +++ b/examples/mevm-confidential-store/main.go @@ -6,6 +6,11 @@ import ( func main() { fr := framework.New() - fr.Suave.DeployContract("confidential-store.sol/ConfidentialStore.json"). - SendConfidentialRequest("example", []interface{}{}, nil) + + namespace := framework.RandomString(10) + ctr := fr.Suave.DeployContract("confidential-store.sol/ConfidentialStore.json") + + ctr.SendConfidentialRequest("example", []interface{}{namespace}, nil) + ctr.SendConfidentialRequest("example2", []interface{}{namespace}, nil) + ctr.SendConfidentialRequest("query", []interface{}{namespace}, nil) } diff --git a/framework/framework.go b/framework/framework.go index c211d36..4871cee 100644 --- a/framework/framework.go +++ b/framework/framework.go @@ -3,6 +3,7 @@ package framework import ( "context" "crypto/ecdsa" + "crypto/rand" "encoding" "encoding/hex" "encoding/json" @@ -349,3 +350,15 @@ func GatewayAddr() string { } return "host.docker.internal" } + +func RandomString(length int) string { + const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + b := make([]byte, length) + if _, err := rand.Read(b); err != nil { + panic(fmt.Errorf("failed to generate random string: %w", err)) + } + for i := range b { + b[i] = charset[b[i]%byte(len(charset))] + } + return string(b) +}