From 94bfc7557ae88b6914b20ec6ced92e860ebcaf8f Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Wed, 8 Nov 2023 13:27:53 -0500 Subject: [PATCH] Fix migration issues and increase test coverage Signed-off-by: Nicko Guyer --- .../postgres/000116_tx_type_not_null.down.sql | 3 + .../postgres/000116_tx_type_not_null.up.sql | 5 + .../sqlite/000116_tx_type_not_null.down.sql | 4 + .../sqlite/000116_tx_type_not_null.up.sql | 5 + go.sum | 1 - internal/blockchain/ethereum/ethereum_test.go | 113 ++++++++++ internal/blockchain/fabric/fabric_test.go | 102 +++++++++ internal/tokens/fftokens/fftokens_test.go | 197 +++++------------- 8 files changed, 281 insertions(+), 149 deletions(-) create mode 100644 db/migrations/postgres/000116_tx_type_not_null.down.sql create mode 100644 db/migrations/postgres/000116_tx_type_not_null.up.sql create mode 100644 db/migrations/sqlite/000116_tx_type_not_null.down.sql create mode 100644 db/migrations/sqlite/000116_tx_type_not_null.up.sql diff --git a/db/migrations/postgres/000116_tx_type_not_null.down.sql b/db/migrations/postgres/000116_tx_type_not_null.down.sql new file mode 100644 index 0000000000..af751ba0d7 --- /dev/null +++ b/db/migrations/postgres/000116_tx_type_not_null.down.sql @@ -0,0 +1,3 @@ +BEGIN; +ALTER TABLE messages ALTER COLUMN tx_parent_type DROP NOT NULL; +COMMIT; diff --git a/db/migrations/postgres/000116_tx_type_not_null.up.sql b/db/migrations/postgres/000116_tx_type_not_null.up.sql new file mode 100644 index 0000000000..6030375bc6 --- /dev/null +++ b/db/migrations/postgres/000116_tx_type_not_null.up.sql @@ -0,0 +1,5 @@ +BEGIN; +UPDATE messages SET tx_parent_type = '' + WHERE tx_parent_type IS NULL; +ALTER TABLE messages ALTER COLUMN tx_parent_type SET NOT NULL; +COMMIT; diff --git a/db/migrations/sqlite/000116_tx_type_not_null.down.sql b/db/migrations/sqlite/000116_tx_type_not_null.down.sql new file mode 100644 index 0000000000..892a01e79c --- /dev/null +++ b/db/migrations/sqlite/000116_tx_type_not_null.down.sql @@ -0,0 +1,4 @@ +ALTER TABLE messages RENAME COLUMN tx_parent_type TO tx_parent_type_temp; +ALTER TABLE messages ADD COLUMN tx_parent_type VARCHAR(64); +UPDATE messages SET tx_parent_type = tx_parent_type_temp; +ALTER TABLE messages DROP COLUMN tx_parent_type_temp; \ No newline at end of file diff --git a/db/migrations/sqlite/000116_tx_type_not_null.up.sql b/db/migrations/sqlite/000116_tx_type_not_null.up.sql new file mode 100644 index 0000000000..1f18a8fa5e --- /dev/null +++ b/db/migrations/sqlite/000116_tx_type_not_null.up.sql @@ -0,0 +1,5 @@ +UPDATE messages SET tx_parent_type = '' WHERE tx_parent_type IS NULL; +ALTER TABLE messages RENAME COLUMN tx_parent_type TO tx_parent_type_temp; +ALTER TABLE messages ADD COLUMN tx_parent_type VARCHAR(64) NOT NULL; +UPDATE messages SET tx_parent_type = tx_parent_type_temp; +ALTER TABLE messages DROP COLUMN tx_parent_type_temp; \ No newline at end of file diff --git a/go.sum b/go.sum index 789faf2b32..c5c653a636 100644 --- a/go.sum +++ b/go.sum @@ -457,7 +457,6 @@ github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2C github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= diff --git a/internal/blockchain/ethereum/ethereum_test.go b/internal/blockchain/ethereum/ethereum_test.go index cab8e6d266..c90591a0c0 100644 --- a/internal/blockchain/ethereum/ethereum_test.go +++ b/internal/blockchain/ethereum/ethereum_test.go @@ -398,6 +398,119 @@ func TestStartStopNamespace(t *testing.T) { assert.NoError(t, err) } +func TestStartStopNamespaceOldEventstream(t *testing.T) { + e, cancel := newTestEthereum() + defer cancel() + + toServer, _, wsURL, done := wsclient.NewTestWSServer(nil) + defer done() + + mockedClient := &http.Client{} + httpmock.ActivateNonDefault(mockedClient) + defer httpmock.DeactivateAndReset() + + u, _ := url.Parse(wsURL) + u.Scheme = "http" + httpURL := u.String() + + httpmock.RegisterResponder("GET", fmt.Sprintf("%s/eventstreams", httpURL), + httpmock.NewJsonResponderOrPanic(200, []eventStream{ + { + ID: "es12345", + Name: "topic1", + }, + })) + httpmock.RegisterResponder("DELETE", fmt.Sprintf("%s/eventstreams/es12345", httpURL), + httpmock.NewJsonResponderOrPanic(204, "")) + httpmock.RegisterResponder("POST", fmt.Sprintf("%s/eventstreams", httpURL), + httpmock.NewJsonResponderOrPanic(200, eventStream{ID: "es12345"})) + + resetConf(e) + utEthconnectConf.Set(ffresty.HTTPConfigURL, httpURL) + utEthconnectConf.Set(ffresty.HTTPCustomClient, mockedClient) + utEthconnectConf.Set(EthconnectConfigInstanceDeprecated, "/instances/0x71C7656EC7ab88b098defB751B7401B5f6d8976F") + utEthconnectConf.Set(EthconnectConfigTopic, "topic1") + utFFTMConf.Set(ffresty.HTTPConfigURL, httpURL) + + cmi := &cachemocks.Manager{} + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) + err := e.Init(e.ctx, e.cancelCtx, utConfig, e.metrics, cmi) + assert.NoError(t, err) + + err = e.StartNamespace(e.ctx, "ns1") + assert.NoError(t, err) + + <-toServer + + err = e.StopNamespace(e.ctx, "ns1") + assert.NoError(t, err) +} + +func TestEnsureEventStreamDeleteFail(t *testing.T) { + e, cancel := newTestEthereum() + defer cancel() + + mockedClient := &http.Client{} + httpmock.ActivateNonDefault(mockedClient) + defer httpmock.DeactivateAndReset() + + httpURL := "http://localhost:12345" + + httpmock.RegisterResponder("GET", fmt.Sprintf("%s/eventstreams", httpURL), + httpmock.NewJsonResponderOrPanic(200, []eventStream{ + { + ID: "es12345", + Name: "topic1", + }, + })) + httpmock.RegisterResponder("DELETE", fmt.Sprintf("%s/eventstreams/es12345", httpURL), + httpmock.NewJsonResponderOrPanic(500, "pop")) + + resetConf(e) + utEthconnectConf.Set(ffresty.HTTPConfigURL, httpURL) + utEthconnectConf.Set(ffresty.HTTPCustomClient, mockedClient) + utEthconnectConf.Set(EthconnectConfigInstanceDeprecated, "/instances/0x71C7656EC7ab88b098defB751B7401B5f6d8976F") + utEthconnectConf.Set(EthconnectConfigTopic, "topic1") + utFFTMConf.Set(ffresty.HTTPConfigURL, httpURL) + + cmi := &cachemocks.Manager{} + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) + err := e.Init(e.ctx, e.cancelCtx, utConfig, e.metrics, cmi) + assert.NoError(t, err) + + _, err = e.streams.ensureEventStream(context.Background(), "topic1/ns1", "topic1") + assert.Regexp(t, "pop", err) +} + +func TestDeleteStreamOKNotFound(t *testing.T) { + e, cancel := newTestEthereum() + defer cancel() + + mockedClient := &http.Client{} + httpmock.ActivateNonDefault(mockedClient) + defer httpmock.DeactivateAndReset() + + httpURL := "http://localhost:12345" + + httpmock.RegisterResponder("DELETE", fmt.Sprintf("%s/eventstreams/es12345", httpURL), + httpmock.NewJsonResponderOrPanic(404, "pop")) + + resetConf(e) + utEthconnectConf.Set(ffresty.HTTPConfigURL, httpURL) + utEthconnectConf.Set(ffresty.HTTPCustomClient, mockedClient) + utEthconnectConf.Set(EthconnectConfigInstanceDeprecated, "/instances/0x71C7656EC7ab88b098defB751B7401B5f6d8976F") + utEthconnectConf.Set(EthconnectConfigTopic, "topic1") + utFFTMConf.Set(ffresty.HTTPConfigURL, httpURL) + + cmi := &cachemocks.Manager{} + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) + err := e.Init(e.ctx, e.cancelCtx, utConfig, e.metrics, cmi) + assert.NoError(t, err) + + err = e.streams.deleteEventStream(context.Background(), "es12345", true) + assert.NoError(t, err) +} + func TestStartNamespaceWSCreateFail(t *testing.T) { e, cancel := newTestEthereum() defer cancel() diff --git a/internal/blockchain/fabric/fabric_test.go b/internal/blockchain/fabric/fabric_test.go index 0ceb494cdd..9b6f82038c 100644 --- a/internal/blockchain/fabric/fabric_test.go +++ b/internal/blockchain/fabric/fabric_test.go @@ -893,6 +893,108 @@ func TestStreamCreateError(t *testing.T) { } +func TestEnsureStreamDelete(t *testing.T) { + + e, cancel := newTestFabric() + defer cancel() + + mockedClient := &http.Client{} + httpmock.ActivateNonDefault(mockedClient) + defer httpmock.DeactivateAndReset() + + httpmock.RegisterResponder("GET", "http://localhost:12345/eventstreams", + httpmock.NewJsonResponderOrPanic(200, []eventStream{ + { + ID: "es12345", + Name: "topic1", + }, + })) + httpmock.RegisterResponder("DELETE", "http://localhost:12345/eventstreams/es12345", + httpmock.NewJsonResponderOrPanic(204, "")) + httpmock.RegisterResponder("POST", "http://localhost:12345/eventstreams", + httpmock.NewStringResponder(200, "")) + resetConf(e) + utFabconnectConf.Set(ffresty.HTTPConfigURL, "http://localhost:12345") + utFabconnectConf.Set(ffresty.HTTPConfigRetryEnabled, false) + utFabconnectConf.Set(ffresty.HTTPCustomClient, mockedClient) + utFabconnectConf.Set(FabconnectConfigChaincodeDeprecated, "firefly") + utFabconnectConf.Set(FabconnectConfigSigner, "signer001") + utFabconnectConf.Set(FabconnectConfigTopic, "topic1") + + cmi := &cachemocks.Manager{} + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) + err := e.Init(e.ctx, e.cancelCtx, utConfig, &metricsmocks.Manager{}, cmi) + assert.NoError(t, err) + + _, err = e.streams.ensureEventStream(context.Background(), "topic1/ns1", "topic1") + assert.NoError(t, err) +} + +func TestEnsureStreamDeleteFail(t *testing.T) { + + e, cancel := newTestFabric() + defer cancel() + + mockedClient := &http.Client{} + httpmock.ActivateNonDefault(mockedClient) + defer httpmock.DeactivateAndReset() + + httpmock.RegisterResponder("GET", "http://localhost:12345/eventstreams", + httpmock.NewJsonResponderOrPanic(200, []eventStream{ + { + ID: "es12345", + Name: "topic1", + }, + })) + httpmock.RegisterResponder("DELETE", "http://localhost:12345/eventstreams/es12345", + httpmock.NewJsonResponderOrPanic(500, "pop")) + resetConf(e) + utFabconnectConf.Set(ffresty.HTTPConfigURL, "http://localhost:12345") + utFabconnectConf.Set(ffresty.HTTPConfigRetryEnabled, false) + utFabconnectConf.Set(ffresty.HTTPCustomClient, mockedClient) + utFabconnectConf.Set(FabconnectConfigChaincodeDeprecated, "firefly") + utFabconnectConf.Set(FabconnectConfigSigner, "signer001") + utFabconnectConf.Set(FabconnectConfigTopic, "topic1") + + cmi := &cachemocks.Manager{} + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) + err := e.Init(e.ctx, e.cancelCtx, utConfig, &metricsmocks.Manager{}, cmi) + assert.NoError(t, err) + + _, err = e.streams.ensureEventStream(context.Background(), "topic1/ns1", "topic1") + assert.Regexp(t, "FF10284.*pop", err) +} + +func TestDeleteStreamOKNotFound(t *testing.T) { + e, cancel := newTestFabric() + defer cancel() + + mockedClient := &http.Client{} + httpmock.ActivateNonDefault(mockedClient) + defer httpmock.DeactivateAndReset() + + httpURL := "http://localhost:12345" + + httpmock.RegisterResponder("DELETE", fmt.Sprintf("%s/eventstreams/es12345", httpURL), + httpmock.NewJsonResponderOrPanic(404, "pop")) + + resetConf(e) + utFabconnectConf.Set(ffresty.HTTPConfigURL, "http://localhost:12345") + utFabconnectConf.Set(ffresty.HTTPConfigRetryEnabled, false) + utFabconnectConf.Set(ffresty.HTTPCustomClient, mockedClient) + utFabconnectConf.Set(FabconnectConfigChaincodeDeprecated, "firefly") + utFabconnectConf.Set(FabconnectConfigSigner, "signer001") + utFabconnectConf.Set(FabconnectConfigTopic, "topic1") + + cmi := &cachemocks.Manager{} + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) + err := e.Init(e.ctx, e.cancelCtx, utConfig, e.metrics, cmi) + assert.NoError(t, err) + + err = e.streams.deleteEventStream(context.Background(), "es12345", true) + assert.NoError(t, err) +} + func TestSubQueryCreateError(t *testing.T) { e, cancel := newTestFabric() diff --git a/internal/tokens/fftokens/fftokens_test.go b/internal/tokens/fftokens/fftokens_test.go index 2f50cdb913..e4ecb0b40d 100644 --- a/internal/tokens/fftokens/fftokens_test.go +++ b/internal/tokens/fftokens/fftokens_test.go @@ -204,6 +204,7 @@ func TestCreateTokenPool(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "requestId": "ns1:" + opID.String(), "signer": "0x123", "type": "fungible", @@ -421,6 +422,7 @@ func TestActivateTokenPool(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolData": "ns1", "poolLocator": "N1", "config": poolConfig, @@ -480,6 +482,7 @@ func TestActivateTokenPoolSynchronous(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolData": "ns1", "poolLocator": "N1", "config": poolConfig, @@ -529,6 +532,7 @@ func TestActivateTokenPoolSynchronousBadResponse(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolData": "ns1", "poolLocator": "N1", "config": poolConfig, @@ -575,6 +579,7 @@ func TestActivateTokenPoolNoContent(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolData": "ns1|" + pool.ID.String(), "poolLocator": "N1", "config": poolConfig, @@ -607,6 +612,7 @@ func TestDeactivateTokenPool(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolData": "ns1|pool1", "poolLocator": "N1", "config": nil, @@ -644,10 +650,11 @@ func TestMintTokens(t *testing.T) { defer done() mint := &core.TokenTransfer{ - LocalID: fftypes.NewUUID(), - To: "user1", - Key: "0x123", - Amount: *fftypes.NewFFBigInt(10), + Namespace: "ns1", + LocalID: fftypes.NewUUID(), + To: "user1", + Key: "0x123", + Amount: *fftypes.NewFFBigInt(10), TX: core.TransactionRef{ ID: fftypes.NewUUID(), Type: core.TransactionTypeTokenTransfer, @@ -666,6 +673,7 @@ func TestMintTokens(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolLocator": "123", "to": "user1", "amount": "10", @@ -700,10 +708,11 @@ func TestMintTokensWithInterface(t *testing.T) { defer done() mint := &core.TokenTransfer{ - LocalID: fftypes.NewUUID(), - To: "user1", - Key: "0x123", - Amount: *fftypes.NewFFBigInt(10), + Namespace: "ns1", + LocalID: fftypes.NewUUID(), + To: "user1", + Key: "0x123", + Amount: *fftypes.NewFFBigInt(10), TX: core.TransactionRef{ ID: fftypes.NewUUID(), Type: core.TransactionTypeTokenTransfer, @@ -723,6 +732,7 @@ func TestMintTokensWithInterface(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolLocator": "123", "to": "user1", "amount": "10", @@ -758,10 +768,11 @@ func TestTokenApproval(t *testing.T) { defer done() approval := &core.TokenApproval{ - LocalID: fftypes.NewUUID(), - Operator: "0x02", - Key: "0x123", - Approved: true, + Namespace: "ns1", + LocalID: fftypes.NewUUID(), + Operator: "0x02", + Key: "0x123", + Approved: true, Config: fftypes.JSONObject{ "foo": "bar", }, @@ -779,6 +790,7 @@ func TestTokenApproval(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolLocator": "123", "operator": "0x02", "approved": true, @@ -841,6 +853,7 @@ func TestBurnTokens(t *testing.T) { defer done() burn := &core.TokenTransfer{ + Namespace: "ns1", LocalID: fftypes.NewUUID(), TokenIndex: "1", From: "user1", @@ -863,6 +876,7 @@ func TestBurnTokens(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolLocator": "123", "tokenIndex": "1", "from": "user1", @@ -912,6 +926,7 @@ func TestTransferTokens(t *testing.T) { defer done() transfer := &core.TokenTransfer{ + Namespace: "ns1", LocalID: fftypes.NewUUID(), TokenIndex: "1", From: "user1", @@ -935,6 +950,7 @@ func TestTransferTokens(t *testing.T) { err := json.NewDecoder(req.Body).Decode(&body) assert.NoError(t, err) assert.Equal(t, fftypes.JSONObject{ + "namespace": "ns1", "poolLocator": "123", "tokenIndex": "1", "from": "user1", @@ -990,149 +1006,21 @@ func TestIgnoredEvents(t *testing.T) { fromServer <- `!}` // ignored fromServer <- `{}` // ignored fromServer <- `{"id":"1"}` // ignored but acked + msg := <-toServer + assert.Equal(t, "{\"type\":\"start\",\"autoack\":null,\"namespace\":\"ns1\",\"name\":\"\",\"ephemeral\":false,\"filter\":{\"message\":{},\"transaction\":{},\"blockchainevent\":{}},\"options\":{}}", string(msg)) + + msg = <-toServer assert.Equal(t, `{"data":{"id":"1"},"event":"ack"}`, string(msg)) fromServer <- fftypes.JSONObject{ - "id": "2", - "event": "receipt", - "data": fftypes.JSONObject{}, + "namespace": "ns1", + "id": "2", + "event": "receipt", + "data": fftypes.JSONObject{}, }.String() } -// func TestBackgroundStartFailWS(t *testing.T) { -// h := &FFTokens{} -// h.InitConfig(ffTokensConfig) - -// // Create a listener and close it - to grab a port we know is not in use -// badListener := httptest.NewServer(&http.ServeMux{}) -// badURL := badListener.URL -// badListener.Close() - -// // Bad url for WS should fail and retry -// ffTokensConfig.AddKnownKey(ffresty.HTTPConfigURL, badURL) -// ffTokensConfig.Set(FFTBackgroundStart, true) -// ffTokensConfig.Set(wsclient.WSConfigKeyInitialConnectAttempts, 1) - -// ctx, cancelCtx := context.WithCancel(context.Background()) -// err := h.Init(ctx, cancelCtx, "testtokens", ffTokensConfig) -// assert.NoError(t, err) - -// capturedErr := make(chan error) -// h.backgroundRetry = &retry.Retry{ -// ErrCallback: func(err error) { -// capturedErr <- err -// }, -// } - -// err = h.Start() -// assert.NoError(t, err) - -// err = <-capturedErr -// assert.Regexp(t, "FF00148", err) -// } - -// func TestReceiptEventsBackgroundStart(t *testing.T) { - -// h, _, fromServer, _, done := newTestFFTokens(t) -// defer done() - -// ffTokensConfig.Set(FFTBackgroundStart, true) - -// err := h.Init(h.ctx, h.cancelCtx, "testtokens", ffTokensConfig) -// assert.NoError(t, err) - -// // Reset the retry to be quicker -// h.backgroundRetry = &retry.Retry{} - -// err = h.Start() -// assert.NoError(t, err) - -// mcb := &coremocks.OperationCallbacks{} -// h.SetOperationHandler("ns1", mcb) -// opID := fftypes.NewUUID() -// mockCalled := make(chan bool) - -// // receipt: bad ID - passed through -// mcb.On("OperationUpdate", mock.MatchedBy(func(update *core.OperationUpdate) bool { -// return update.NamespacedOpID == "ns1:wrong" && -// update.Status == core.OpStatusPending && -// update.Plugin == "fftokens" -// })).Return(nil).Once().Run(func(args mock.Arguments) { mockCalled <- true }) -// fromServer <- fftypes.JSONObject{ -// "id": "3", -// "event": "receipt", -// "data": fftypes.JSONObject{ -// "headers": fftypes.JSONObject{ -// "requestId": "ns1:wrong", // passed through to OperationUpdate to ignore -// "type": "TransactionUpdate", -// }, -// }, -// }.String() -// <-mockCalled - -// // receipt: success -// mcb.On("OperationUpdate", mock.MatchedBy(func(update *core.OperationUpdate) bool { -// return update.NamespacedOpID == "ns1:"+opID.String() && -// update.Status == core.OpStatusSucceeded && -// update.BlockchainTXID == "0xffffeeee" && -// update.Plugin == "fftokens" -// })).Return(nil).Once().Run(func(args mock.Arguments) { mockCalled <- true }) -// fromServer <- fftypes.JSONObject{ -// "id": "4", -// "event": "receipt", -// "data": fftypes.JSONObject{ -// "headers": fftypes.JSONObject{ -// "requestId": "ns1:" + opID.String(), -// "type": "TransactionSuccess", -// }, -// "transactionHash": "0xffffeeee", -// }, -// }.String() -// <-mockCalled - -// // receipt: update -// mcb.On("OperationUpdate", mock.MatchedBy(func(update *core.OperationUpdate) bool { -// return update.NamespacedOpID == "ns1:"+opID.String() && -// update.Status == core.OpStatusPending && -// update.BlockchainTXID == "0xffffeeee" -// })).Return(nil).Once().Run(func(args mock.Arguments) { mockCalled <- true }) -// fromServer <- fftypes.JSONObject{ -// "id": "5", -// "event": "receipt", -// "data": fftypes.JSONObject{ -// "headers": fftypes.JSONObject{ -// "requestId": "ns1:" + opID.String(), -// "type": "TransactionUpdate", -// }, -// "transactionHash": "0xffffeeee", -// }, -// }.String() -// <-mockCalled - -// // receipt: failure -// mcb.On("OperationUpdate", mock.MatchedBy(func(update *core.OperationUpdate) bool { -// return update.NamespacedOpID == "ns1:"+opID.String() && -// update.Status == core.OpStatusFailed && -// update.BlockchainTXID == "0xffffeeee" && -// update.Plugin == "fftokens" -// })).Return(nil).Once().Run(func(args mock.Arguments) { mockCalled <- true }) -// fromServer <- fftypes.JSONObject{ -// "id": "5", -// "event": "receipt", -// "data": fftypes.JSONObject{ -// "headers": fftypes.JSONObject{ -// "requestId": "ns1:" + opID.String(), -// "type": "TransactionFailed", -// }, -// "transactionHash": "0xffffeeee", -// }, -// }.String() -// <-mockCalled - -// mcb.AssertExpectations(t) -// } - func TestReceiptEvents(t *testing.T) { h, _, fromServer, _, done := newTestFFTokens(t) defer done() @@ -1241,7 +1129,11 @@ func TestPoolEvents(t *testing.T) { "id": "6", "event": "token-pool", }.String() + msg := <-toServer + assert.Equal(t, "{\"type\":\"start\",\"autoack\":null,\"namespace\":\"ns1\",\"name\":\"\",\"ephemeral\":false,\"filter\":{\"message\":{},\"transaction\":{},\"blockchainevent\":{}},\"options\":{}}", string(msg)) + + msg = <-toServer assert.Equal(t, `{"data":{"id":"6"},"event":"ack"}`, string(msg)) // token-pool: invalid uuid (success) @@ -1252,6 +1144,7 @@ func TestPoolEvents(t *testing.T) { "id": "7", "event": "token-pool", "data": fftypes.JSONObject{ + "namespace": "ns1", "id": "000000000010/000020/000030/000040", "type": "fungible", "poolLocator": "F1", @@ -1357,7 +1250,11 @@ func TestTransferEvents(t *testing.T) { "id": "9", "event": "token-mint", }.String() + msg := <-toServer + assert.Equal(t, "{\"type\":\"start\",\"autoack\":null,\"namespace\":\"ns1\",\"name\":\"\",\"ephemeral\":false,\"filter\":{\"message\":{},\"transaction\":{},\"blockchainevent\":{}},\"options\":{}}", string(msg)) + + msg = <-toServer assert.Equal(t, `{"data":{"id":"9"},"event":"ack"}`, string(msg)) // token-mint: invalid amount @@ -1600,7 +1497,11 @@ func TestApprovalEvents(t *testing.T) { }, }, }.String() + msg := <-toServer + assert.Equal(t, "{\"type\":\"start\",\"autoack\":null,\"namespace\":\"ns1\",\"name\":\"\",\"ephemeral\":false,\"filter\":{\"message\":{},\"transaction\":{},\"blockchainevent\":{}},\"options\":{}}", string(msg)) + + msg = <-toServer assert.Equal(t, `{"data":{"id":"17"},"event":"ack"}`, string(msg)) // token-approval: success (no data)