From 771f31b418827255649bd919a6e9f728b3f2cda9 Mon Sep 17 00:00:00 2001 From: huangzhiran Date: Tue, 7 Jan 2025 16:04:41 +0800 Subject: [PATCH 1/2] e2e support movement --- .gitattributes | 2 + .github/workflows/e2e-test.yml | 1 + e2e/e2e_test.go | 61 +++++++++++++++++++++++- e2e/testdata/geodnet.circuit | 3 ++ e2e/testdata/geodnet.pk | 3 ++ service/apinode/aggregator/aggregator.go | 2 +- vm/payload.go | 12 ++--- 7 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 .gitattributes create mode 100644 e2e/testdata/geodnet.circuit create mode 100644 e2e/testdata/geodnet.pk diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..ce12b49a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.circuit filter=lfs diff=lfs merge=lfs -text +*.pk filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index b68cbffa..aa92f87e 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -22,6 +22,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 + lfs: true - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 5f7a8d47..f85aefbe 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -128,7 +128,7 @@ func TestE2E(t *testing.T) { sendETH(t, chainEndpoint, payerHex, deviceAddr, 20) //registerIoID(t, chainEndpoint, contracts, deviceKey, projectID) - t.Run("GNARK", func(t *testing.T) { + t.Run("gnark", func(t *testing.T) { // Register project projectOwnerKey, err := crypto.GenerateKey() require.NoError(t, err) @@ -152,7 +152,7 @@ func TestE2E(t *testing.T) { taskid := sendMessage(t, data, projectID, nil, deviceKey, apiNodeUrl) waitSettled(t, taskid, apiNodeUrl) }) - t.Run("GNARK-liveness", func(t *testing.T) { + t.Run("gnark-liveness", func(t *testing.T) { // Register project projectOwnerKey, err := crypto.GenerateKey() require.NoError(t, err) @@ -186,6 +186,63 @@ func TestE2E(t *testing.T) { taskid := sendMessage(t, data, projectID, project.Configs[0], deviceKey, apiNodeUrl) waitSettled(t, taskid, apiNodeUrl) }) + t.Run("gnark-movement", func(t *testing.T) { + // Register project + projectOwnerKey, err := crypto.GenerateKey() + require.NoError(t, err) + projectOwnerAddr := crypto.PubkeyToAddress(projectOwnerKey.PublicKey) + sendETH(t, chainEndpoint, payerHex, projectOwnerAddr, 20) + projectID := big.NewInt(3) + registerIoID(t, chainEndpoint, contracts, deviceKey, projectID) + registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDappLiveness)) + + gnarkCodePath := "./testdata/geodnet.circuit" + gnarkMetadataPath := "./testdata/geodnet.pk" + project := &project.Project{Configs: []*project.Config{{ + Version: "v1", + VMTypeID: 1, + SignedKeys: []project.SignedKey{ + {Name: "timestamp", Type: "uint64"}, + {Name: "latitude", Type: "uint64"}, + {Name: "longitude", Type: "uint64"}}, + }}} + + uploadProject(t, chainEndpoint, ipfsEndpoint, project, &gnarkCodePath, &gnarkMetadataPath, contracts, projectOwnerKey, projectID) + + // Wait a few seconds for the device info synced on api node + time.Sleep(2 * time.Second) + + timestamp := uint64(time.Now().Unix()) + lastTimestamp := timestamp - 60 + latitude := uint64(1200) + longitude := uint64(200) + lastLatitude := latitude - 1100 + lastLongitude := longitude - 1 + + data, err := json.Marshal(struct { + Timestamp uint64 `json:"timestamp"` + Latitude uint64 `json:"latitude"` + Longitude uint64 `json:"longitude"` + }{ + Timestamp: timestamp, + Latitude: latitude, + Longitude: longitude, + }) + require.NoError(t, err) + lastData, err := json.Marshal(struct { + Timestamp uint64 `json:"timestamp"` + Latitude uint64 `json:"latitude"` + Longitude uint64 `json:"longitude"` + }{ + Timestamp: lastTimestamp, + Latitude: lastLatitude, + Longitude: lastLongitude, + }) + require.NoError(t, err) + _ = sendMessage(t, lastData, projectID, project.Configs[0], deviceKey, apiNodeUrl) + taskID := sendMessage(t, data, projectID, project.Configs[0], deviceKey, apiNodeUrl) + waitSettled(t, taskID, apiNodeUrl) + }) } func sendMessage(t *testing.T, dataJson []byte, projectID *big.Int, diff --git a/e2e/testdata/geodnet.circuit b/e2e/testdata/geodnet.circuit new file mode 100644 index 00000000..8a371ca1 --- /dev/null +++ b/e2e/testdata/geodnet.circuit @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae33b4b5ce392ba4e0f6c2590e6b6180302df6c881acb22231872dce3faaad9d +size 29671791 diff --git a/e2e/testdata/geodnet.pk b/e2e/testdata/geodnet.pk new file mode 100644 index 00000000..b05dc414 --- /dev/null +++ b/e2e/testdata/geodnet.pk @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b96d85d2ff1d869561bede009e4af361f52d28d560021679f87af0a4468979f +size 122624679 diff --git a/service/apinode/aggregator/aggregator.go b/service/apinode/aggregator/aggregator.go index 3395ab02..b4000570 100644 --- a/service/apinode/aggregator/aggregator.go +++ b/service/apinode/aggregator/aggregator.go @@ -32,7 +32,7 @@ func Run(db *apidb.DB, sequencerAddr string, interval time.Duration) { tasksbyProject[ts[i].ProjectID] = append(tasksbyProject[ts[i].ProjectID], ts[i]) } - if tasks, ok := tasksbyProject["942"]; ok && len(tasks) > 0 { + if tasks, ok := tasksbyProject["3"]; ok && len(tasks) > 0 { prevTaskID := tasks[0].TaskID tasks[len(tasks)-1].PrevTaskID = prevTaskID } diff --git a/vm/payload.go b/vm/payload.go index f4414014..6d22b1ee 100644 --- a/vm/payload.go +++ b/vm/payload.go @@ -20,18 +20,12 @@ var ( ) func LoadPayload(task *task.Task, projectConfig *project.Config) ([]byte, error) { - if len(projectConfig.SignedKeys) > 0 { + if l := len(projectConfig.SignedKeys); l == 1 { return encodePebblePayload(task, projectConfig) + } else if l > 1 { + return encodeGeodnetPayload(task, projectConfig) } return task.Payload, nil - // switch task.ProjectID.String() { - // case _pebbleProjectID.String(): - return encodePebblePayload(task, projectConfig) - // case _geoProjectID.String(): - // return encodeGeodnetPayload(task, projectConfig) - // default: - // return task.Payload, nil - // } } type ProofofLivenessCircuit struct { From cf2e21173e14448ba9d0d678b139f99e24dcaeb4 Mon Sep 17 00:00:00 2001 From: huangzhiran Date: Tue, 7 Jan 2025 16:15:05 +0800 Subject: [PATCH 2/2] change dapp contarct --- e2e/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index f85aefbe..cfba7c07 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -194,7 +194,7 @@ func TestE2E(t *testing.T) { sendETH(t, chainEndpoint, payerHex, projectOwnerAddr, 20) projectID := big.NewInt(3) registerIoID(t, chainEndpoint, contracts, deviceKey, projectID) - registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDappLiveness)) + registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDapp)) gnarkCodePath := "./testdata/geodnet.circuit" gnarkMetadataPath := "./testdata/geodnet.pk"