Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
arnauds5 committed Jun 26, 2024
1 parent ddb7338 commit a8cb6e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func Test_handleChannelFederation(t *testing.T) {
laoPath := fmt.Sprintf("/root/%s", laoID)
channelPath := fmt.Sprintf("/root/%s/federation", laoID)

rollcallId := "fEvAfdtNrykd9NPYl9ReHLX-6IP6SFLKTZJLeGUHZ_U="
tokens := []string{organizer}

serverAddressA := "ws://localhost:9801/client"
value := "82eadde2a4ba832518b90bb93c8480ee1ae16a91d5efe9281e91e2ec11da03e4"
validUntil := time.Now().Add(5 * time.Minute).Unix()
Expand Down Expand Up @@ -318,6 +321,16 @@ func Test_handleChannelFederation(t *testing.T) {
contains: "sql: no rows in result set",
})

// Test 19 Error when token exchange sender is not the organizerPk
args = append(args, input{
name: "Test 19",
channelPath: channelPath,
msg: generator.NewTokensExchange(t, notOrganizer, laoID, rollcallId,
time.Now().Unix(), tokens, notOrganizerSk),
isError: true,
contains: "sender is not the organizer of the channelPath",
})

for _, arg := range args {
t.Run(arg.name, func(t *testing.T) {
err = federationHandler.Handle(arg.channelPath, arg.msg, &fakeSocket)
Expand Down
19 changes: 19 additions & 0 deletions be1-go/internal/test/generator/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,22 @@ func NewFailedFederationResult(t *testing.T, sender, reason string,

return msg
}

func NewTokensExchange(t *testing.T, sender, laoId, rollcallId string,
timestamp int64, tokens []string, senderSk kyber.Scalar) mmessage.Message {
tokensExchange := mfederation.FederationTokensExchange{
Object: channel.FederationObject,
Action: channel.FederationActionTokensExchange,
LaoId: laoId,
RollcallId: rollcallId,
Timestamp: timestamp,
Tokens: tokens,
}

tokensExchangeBuf, err := json.Marshal(tokensExchange)
require.NoError(t, err)

msg := newMessage(t, sender, senderSk, tokensExchangeBuf)

return msg
}

0 comments on commit a8cb6e5

Please sign in to comment.