Skip to content

Commit

Permalink
Use channel signer to verify channel state request sender
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbogd committed Dec 3, 2018
1 parent 45a7231 commit 506fbb8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions escrow/state_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (service *PaymentChannelStateService) GetChannelState(context context.Conte
return nil, fmt.Errorf("channel is not found, channelId: %v", channelID)
}

if channel.Sender != *sender {
return nil, errors.New("only channel sender can get latest channel state")
if channel.Signer != *sender {
return nil, errors.New("only channel signer can get latest channel state")
}

if channel.Signature == nil {
Expand Down
13 changes: 5 additions & 8 deletions escrow/state_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

type stateServiceTestType struct {
service PaymentChannelStateService
senderPrivateKey *ecdsa.PrivateKey
senderAddress common.Address
signerPrivateKey *ecdsa.PrivateKey
signerAddress common.Address
Expand All @@ -28,8 +27,7 @@ type stateServiceTestType struct {

var stateServiceTest = func() stateServiceTestType {
channelServiceMock := &paymentChannelServiceMock{}
senderPrivateKey := GenerateTestPrivateKey()
senderAddress := crypto.PubkeyToAddress(senderPrivateKey.PublicKey)
senderAddress := crypto.PubkeyToAddress(GenerateTestPrivateKey().PublicKey)
signerPrivateKey := GenerateTestPrivateKey()
signerAddress := crypto.PubkeyToAddress(signerPrivateKey.PublicKey)

Expand All @@ -43,7 +41,6 @@ var stateServiceTest = func() stateServiceTestType {
service: PaymentChannelStateService{
channelService: channelServiceMock,
},
senderPrivateKey: senderPrivateKey,
senderAddress: senderAddress,
signerPrivateKey: signerPrivateKey,
signerAddress: signerAddress,
Expand All @@ -61,7 +58,7 @@ var stateServiceTest = func() stateServiceTestType {
},
defaultRequest: &ChannelStateRequest{
ChannelId: bigIntToBytes(defaultChannelId),
Signature: getSignature(bigIntToBytes(defaultChannelId), senderPrivateKey),
Signature: getSignature(bigIntToBytes(defaultChannelId), signerPrivateKey),
},
defaultReply: &ChannelStateReply{
CurrentNonce: bigIntToBytes(big.NewInt(3)),
Expand Down Expand Up @@ -96,7 +93,7 @@ func TestGetChannelStateChannelIdIsNotPaddedByZero(t *testing.T) {
nil,
&ChannelStateRequest{
ChannelId: []byte{0xFF},
Signature: getSignature(bigIntToBytes(channelId), stateServiceTest.senderPrivateKey),
Signature: getSignature(bigIntToBytes(channelId), stateServiceTest.signerPrivateKey),
},
)

Expand Down Expand Up @@ -135,7 +132,7 @@ func TestGetChannelStateChannelNotFound(t *testing.T) {
nil,
&ChannelStateRequest{
ChannelId: bigIntToBytes(channelId),
Signature: getSignature(bigIntToBytes(channelId), stateServiceTest.senderPrivateKey),
Signature: getSignature(bigIntToBytes(channelId), stateServiceTest.signerPrivateKey),
},
)

Expand All @@ -160,7 +157,7 @@ func TestGetChannelStateIncorrectSender(t *testing.T) {
},
)

assert.Equal(t, errors.New("only channel sender can get latest channel state"), err)
assert.Equal(t, errors.New("only channel signer can get latest channel state"), err)
assert.Nil(t, reply)
}

Expand Down

0 comments on commit 506fbb8

Please sign in to comment.