Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dxoperations
Browse files Browse the repository at this point in the history
  • Loading branch information
awrichar committed Aug 1, 2022
2 parents be59baf + 8820037 commit 65301b9
Showing 1 changed file with 162 additions and 0 deletions.
162 changes: 162 additions & 0 deletions internal/operations/operation_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,28 @@ func TestSubmitUpdateSyncFallbackOpNotFound(t *testing.T) {
}).Return(nil)
mdi.On("GetOperations", customCtx, mock.Anything, mock.Anything).Return(nil, nil, nil)

complete := false
ou.SubmitOperationUpdate(customCtx, &core.OperationUpdate{
NamespacedOpID: "ns1:" + fftypes.NewUUID().String(),
OnComplete: func() { complete = true },
})
assert.True(t, complete)

mdi.AssertExpectations(t)
}

func TestSubmitUpdateDatabaseError(t *testing.T) {
ou := newTestOperationUpdaterNoConcurrency(t)
defer ou.close()

ctx, cancel := context.WithCancel(context.Background())
cancel()

mdi := ou.database.(*databasemocks.Plugin)
mdi.On("RunAsGroup", mock.Anything, mock.Anything).Return(fmt.Errorf("pop"))

ou.SubmitOperationUpdate(ctx, &core.OperationUpdate{
NamespacedOpID: "ns1:" + fftypes.NewUUID().String(),
})

mdi.AssertExpectations(t)
Expand Down Expand Up @@ -325,3 +345,145 @@ func TestDoUpdateFailExternalHandler(t *testing.T) {
}, []*core.Transaction{})
assert.Regexp(t, "pop", err)
}

func TestDoUpdateVerifyBatchManifest(t *testing.T) {
ou := newTestOperationUpdaterNoConcurrency(t)
defer ou.close()

opID1 := fftypes.NewUUID()
txID1 := fftypes.NewUUID()
batchID := fftypes.NewUUID()
ou.manager.handlers[core.OpTypeDataExchangeSendBatch] = &mockHandler{}

ou.initQueues()

mdi := ou.database.(*databasemocks.Plugin)
mdi.On("GetBatchByID", mock.Anything, "ns1", batchID).Return(&core.BatchPersisted{
Manifest: fftypes.JSONAnyPtr(`"test-manifest"`),
}, nil)
mdi.On("ResolveOperation", mock.Anything, "ns1", opID1, core.OpStatusSucceeded, mock.Anything, fftypes.JSONObject(nil)).Return(nil)

err := ou.doUpdate(ou.ctx, &core.OperationUpdate{
NamespacedOpID: "ns1:" + opID1.String(),
Status: core.OpStatusSucceeded,
VerifyManifest: true,
DXManifest: `"test-manifest"`,
}, []*core.Operation{{
Namespace: "ns1",
ID: opID1,
Type: core.OpTypeDataExchangeSendBatch,
Transaction: txID1,
Input: fftypes.JSONObject{
"batch": batchID.String(),
},
}}, []*core.Transaction{})

assert.NoError(t, err)

mdi.AssertExpectations(t)
}

func TestDoUpdateVerifyBatchManifestQuery(t *testing.T) {
ou := newTestOperationUpdaterNoConcurrency(t)
defer ou.close()

opID1 := fftypes.NewUUID()
txID1 := fftypes.NewUUID()
batchID := fftypes.NewUUID()
ou.manager.handlers[core.OpTypeDataExchangeSendBatch] = &mockHandler{}

ou.initQueues()

mdi := ou.database.(*databasemocks.Plugin)
mdi.On("GetBatchByID", mock.Anything, "ns1", batchID).Return(nil, fmt.Errorf("pop"))

err := ou.doUpdate(ou.ctx, &core.OperationUpdate{
NamespacedOpID: "ns1:" + opID1.String(),
Status: core.OpStatusSucceeded,
VerifyManifest: true,
DXManifest: `"test-manifest"`,
}, []*core.Operation{{
Namespace: "ns1",
ID: opID1,
Type: core.OpTypeDataExchangeSendBatch,
Transaction: txID1,
Input: fftypes.JSONObject{
"batch": batchID.String(),
},
}}, []*core.Transaction{})

assert.EqualError(t, err, "pop")

mdi.AssertExpectations(t)
}

func TestDoUpdateVerifyBatchManifestFail(t *testing.T) {
ou := newTestOperationUpdaterNoConcurrency(t)
defer ou.close()

opID1 := fftypes.NewUUID()
txID1 := fftypes.NewUUID()
batchID := fftypes.NewUUID()
ou.manager.handlers[core.OpTypeDataExchangeSendBatch] = &mockHandler{}

ou.initQueues()

mdi := ou.database.(*databasemocks.Plugin)
mdi.On("GetBatchByID", mock.Anything, "ns1", batchID).Return(&core.BatchPersisted{
Manifest: fftypes.JSONAnyPtr(`"test-manifest"`),
}, nil)
mdi.On("ResolveOperation", mock.Anything, "ns1", opID1, core.OpStatusFailed, mock.Anything, fftypes.JSONObject(nil)).Return(nil)

err := ou.doUpdate(ou.ctx, &core.OperationUpdate{
NamespacedOpID: "ns1:" + opID1.String(),
Status: core.OpStatusSucceeded,
VerifyManifest: true,
DXManifest: `"BAD"`,
}, []*core.Operation{{
Namespace: "ns1",
ID: opID1,
Type: core.OpTypeDataExchangeSendBatch,
Transaction: txID1,
Input: fftypes.JSONObject{
"batch": batchID.String(),
},
}}, []*core.Transaction{})

assert.NoError(t, err)

mdi.AssertExpectations(t)
}

func TestDoUpdateVerifyBlobManifestFail(t *testing.T) {
ou := newTestOperationUpdaterNoConcurrency(t)
defer ou.close()

opID1 := fftypes.NewUUID()
txID1 := fftypes.NewUUID()
blobHash := fftypes.NewRandB32()
ou.manager.handlers[core.OpTypeDataExchangeSendBlob] = &mockHandler{}

ou.initQueues()

mdi := ou.database.(*databasemocks.Plugin)
mdi.On("ResolveOperation", mock.Anything, "ns1", opID1, core.OpStatusFailed, mock.Anything, fftypes.JSONObject(nil)).Return(nil)

err := ou.doUpdate(ou.ctx, &core.OperationUpdate{
NamespacedOpID: "ns1:" + opID1.String(),
Status: core.OpStatusSucceeded,
VerifyManifest: true,
DXHash: "BAD",
}, []*core.Operation{{
Namespace: "ns1",
ID: opID1,
Type: core.OpTypeDataExchangeSendBlob,
Transaction: txID1,
Input: fftypes.JSONObject{
"hash": blobHash.String(),
},
}}, []*core.Transaction{})

assert.NoError(t, err)

mdi.AssertExpectations(t)
}

0 comments on commit 65301b9

Please sign in to comment.