Skip to content

Commit

Permalink
e2e support movement (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhiran authored Jan 7, 2025
1 parent 0050a84 commit 83c3aea
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.circuit filter=lfs diff=lfs merge=lfs -text
*.pk filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 59 additions & 2 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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.MockDapp))

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,
Expand Down
3 changes: 3 additions & 0 deletions e2e/testdata/geodnet.circuit
Git LFS file not shown
3 changes: 3 additions & 0 deletions e2e/testdata/geodnet.pk
Git LFS file not shown
2 changes: 1 addition & 1 deletion service/apinode/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 3 additions & 9 deletions vm/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 83c3aea

Please sign in to comment.