Skip to content

Commit

Permalink
Add some additional test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Jun 24, 2022
1 parent d4bf6d6 commit b452654
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 5 deletions.
67 changes: 67 additions & 0 deletions internal/assets/token_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,39 @@ func TestTransferTokensWithBroadcastMessage(t *testing.T) {
mom.AssertExpectations(t)
}

func TestTransferTokensWithBroadcastMessageDisabled(t *testing.T) {
am, cancel := newTestAssets(t)
defer cancel()
am.broadcast = nil

msgID := fftypes.NewUUID()
hash := fftypes.NewRandB32()
transfer := &core.TokenTransferInput{
TokenTransfer: core.TokenTransfer{
From: "A",
To: "B",
Amount: *fftypes.NewFFBigInt(5),
},
Pool: "pool1",
Message: &core.MessageInOut{
Message: core.Message{
Header: core.MessageHeader{
ID: msgID,
},
Hash: hash,
},
InlineData: core.InlineData{
{
Value: fftypes.JSONAnyPtr("test data"),
},
},
},
}

_, err := am.TransferTokens(context.Background(), transfer, false)
assert.Regexp(t, "FF10415", err)
}

func TestTransferTokensWithBroadcastMessageSendFail(t *testing.T) {
am, cancel := newTestAssets(t)
defer cancel()
Expand Down Expand Up @@ -907,6 +940,40 @@ func TestTransferTokensWithPrivateMessage(t *testing.T) {
mom.AssertExpectations(t)
}

func TestTransferTokensWithPrivateMessageDisabled(t *testing.T) {
am, cancel := newTestAssets(t)
defer cancel()
am.messaging = nil

msgID := fftypes.NewUUID()
hash := fftypes.NewRandB32()
transfer := &core.TokenTransferInput{
TokenTransfer: core.TokenTransfer{
From: "A",
To: "B",
Amount: *fftypes.NewFFBigInt(5),
},
Pool: "pool1",
Message: &core.MessageInOut{
Message: core.Message{
Header: core.MessageHeader{
ID: msgID,
Type: core.MessageTypeTransferPrivate,
},
Hash: hash,
},
InlineData: core.InlineData{
{
Value: fftypes.JSONAnyPtr("test data"),
},
},
},
}

_, err := am.TransferTokens(context.Background(), transfer, false)
assert.Regexp(t, "FF10415", err)
}

func TestTransferTokensWithInvalidMessage(t *testing.T) {
am, cancel := newTestAssets(t)
defer cancel()
Expand Down
23 changes: 23 additions & 0 deletions internal/data/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ func TestUploadBlobOk(t *testing.T) {

}

func TestUploadBlobDisabled(t *testing.T) {

dm, ctx, cancel := newTestDataManager(t)
defer cancel()
dm.exchange = nil

b := make([]byte, 10)
_, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader(b)}, false)
assert.Regexp(t, "FF10414", err)

}

func TestUploadBlobAutoMetaOk(t *testing.T) {

dm, ctx, cancel := newTestDataManager(t)
Expand Down Expand Up @@ -283,6 +295,17 @@ func TestDownloadBlobOk(t *testing.T) {

}

func TestDownloadBlobDisabled(t *testing.T) {

dm, ctx, cancel := newTestDataManager(t)
defer cancel()
dm.exchange = nil

_, _, err := dm.DownloadBlob(ctx, "")
assert.Regexp(t, "FF10414", err)

}

func TestDownloadBlobNotFound(t *testing.T) {

dm, ctx, cancel := newTestDataManager(t)
Expand Down
20 changes: 20 additions & 0 deletions internal/events/batch_pin_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,26 @@ func TestBatchPinCompleteWrongNamespace(t *testing.T) {
assert.NoError(t, err)
}

func TestBatchPinCompleteNonMultiparty(t *testing.T) {
em, cancel := newTestEventManager(t)
defer cancel()
em.multiparty = nil

batch := &blockchain.BatchPin{
Namespace: "ns1",
TransactionID: fftypes.NewUUID(),
Event: blockchain.Event{
BlockchainTXID: "0x12345",
},
}

err := em.BatchPinComplete(batch, &core.VerifierRef{
Type: core.VerifierTypeEthAddress,
Value: "0x12345",
})
assert.NoError(t, err)
}

func TestPersistBatchMissingID(t *testing.T) {
em, cancel := newTestEventManager(t)
defer cancel()
Expand Down
17 changes: 17 additions & 0 deletions internal/events/dx_callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ func TestMessageReceivedWrongNS(t *testing.T) {

}

func TestMessageReceivedNonMultiparty(t *testing.T) {
em, cancel := newTestEventManager(t)
defer cancel()
em.multiparty = nil

_, b := sampleBatchTransfer(t, core.TransactionTypeBatchPin)

mdx := &dataexchangemocks.Plugin{}
mdx.On("Name").Return("utdx")

mde := newMessageReceived("peer1", b, "")
em.messageReceived(mdx, mde)

mde.AssertExpectations(t)

}

func TestMessageReceiveNodeLookupError(t *testing.T) {
em, cancel := newTestEventManager(t)
cancel() // to stop retry
Expand Down
34 changes: 34 additions & 0 deletions internal/events/reply_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,37 @@ func TestSendReplyPrivateOk(t *testing.T) {
mpm.AssertExpectations(t)
mms.AssertExpectations(t)
}

func TestSendReplyBroadcastDisabled(t *testing.T) {
ed, cancel := newTestEventDispatcher(&subscription{
definition: &core.Subscription{},
})
defer cancel()
ed.broadcast = nil

ed.sendReply(context.Background(), &core.Event{
ID: fftypes.NewUUID(),
Namespace: "ns1",
}, &core.MessageInOut{})
}

func TestSendReplyPrivateDisabled(t *testing.T) {
ed, cancel := newTestEventDispatcher(&subscription{
definition: &core.Subscription{},
})
defer cancel()
ed.messaging = nil

msg := &core.Message{
Header: core.MessageHeader{
Group: fftypes.NewRandB32(),
},
}

ed.sendReply(context.Background(), &core.Event{
ID: fftypes.NewUUID(),
Namespace: "ns1",
}, &core.MessageInOut{
Message: *msg,
})
}
18 changes: 18 additions & 0 deletions internal/events/ss_callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ func TestSharedStorageBatchDownloadedNSMismatch(t *testing.T) {

}

func TestSharedStorageBatchDownloadedNonMultiparty(t *testing.T) {

em, cancel := newTestEventManager(t)
defer cancel()
em.multiparty = nil

data := &core.Data{ID: fftypes.NewUUID(), Value: fftypes.JSONAnyPtr(`"test"`)}
batch := sampleBatch(t, core.BatchTypeBroadcast, core.TransactionTypeBatchPin, core.DataArray{data})
b, _ := json.Marshal(&batch)

mss := &sharedstoragemocks.Plugin{}
_, err := em.SharedStorageBatchDownloaded(mss, "payload1", b)
assert.NoError(t, err)

mss.AssertExpectations(t)

}

func TestSharedStorageBatchDownloadedBadData(t *testing.T) {

em, cancel := newTestEventManager(t)
Expand Down
6 changes: 1 addition & 5 deletions internal/orchestrator/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ import (
)

func (or *orchestrator) RequestReply(ctx context.Context, msg *core.MessageInOut) (reply *core.MessageInOut, err error) {
pm := or.PrivateMessaging()
if pm == nil {
return nil, i18n.NewError(ctx, coremsgs.MsgMessagesNotSupported)
}
if msg.Header.Group == nil && (msg.Group == nil || len(msg.Group.Members) == 0) {
return nil, i18n.NewError(ctx, coremsgs.MsgRequestMustBePrivate)
}
return pm.RequestReply(ctx, msg)
return or.PrivateMessaging().RequestReply(ctx, msg)
}

0 comments on commit b452654

Please sign in to comment.