Skip to content

Commit f28fe70

Browse files
committed
feat: Redeem unit testing
Signed-off-by: Allon Adir <adir@il.ibm.com>
1 parent 9f52996 commit f28fe70

File tree

8 files changed

+28
-4
lines changed

8 files changed

+28
-4
lines changed

token/core/fabtoken/v1/actions/transfer_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,12 @@ func TestTransferAction_Serialization(t *testing.T) {
273273
assert.NoError(t, err, "failed to deserialize a new transfer action")
274274
assert.Equal(t, action2, action3, "deserialized action is not equal to the original one")
275275
}
276+
277+
func TestTransferAction_GetIssuer(t *testing.T) {
278+
issuerId := []byte("issuer")
279+
action := &TransferAction{
280+
Issuer: issuerId,
281+
}
282+
issuer := action.GetIssuer()
283+
assert.True(t, issuer.Equal(issuerId), "unexpected issuer id in TransferAction")
284+
}

token/core/fabtoken/v1/setup/setup_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111

1212
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
13-
1413
"github.com/stretchr/testify/assert"
1514
)
1615

token/core/fabtoken/v1/transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func NewTransferService(
4646
// Transfer returns a TransferAction as a function of the passed arguments
4747
// It also returns the corresponding TransferMetadata
4848
func (s *TransferService) Transfer(ctx context.Context, _ string, _ driver.OwnerWallet, tokenIDs []*token.ID, Outputs []*token.Token, opts *driver.TransferOptions) (driver.TransferAction, *driver.TransferMetadata, error) {
49-
var isRedeem bool
5049
// select inputs
5150
inputTokens, err := s.TokenLoader.GetTokens(tokenIDs)
5251
if err != nil {
@@ -61,6 +60,7 @@ func (s *TransferService) Transfer(ctx context.Context, _ string, _ driver.Owner
6160
}
6261

6362
// prepare outputs
63+
var isRedeem bool
6464
var outs []*actions.Output
6565
for _, output := range Outputs {
6666
outs = append(outs, &actions.Output{

token/core/fabtoken/v1/validator/validator_transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func TransferSignatureValidate(ctx *Context) error {
3030
return errors.Errorf("invalid number of token inputs, expected at least 1")
3131
}
3232

33-
var isRedeem bool
3433
var inputToken []*actions.Output
3534
for _, in := range ctx.TransferAction.Inputs {
3635
tok := in.Input
@@ -51,6 +50,7 @@ func TransferSignatureValidate(ctx *Context) error {
5150
ctx.Signatures = append(ctx.Signatures, sigma)
5251
}
5352

53+
var isRedeem bool
5454
for _, output := range ctx.TransferAction.Outputs {
5555
if output.Owner == nil {
5656
isRedeem = true

token/core/zkatdlog/nogh/v1/transfer/action_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ func TestAction_Validate(t *testing.T) {
379379
Data: &math.G1{},
380380
},
381381
},
382+
Issuer: []byte("issuer"),
382383
},
383384
wantErr: false,
384385
},
@@ -488,5 +489,15 @@ func randomAction(curve *math.Curve, rand io.Reader, b assert.TestingT) *Action
488489
"key1": getRandomBytes(b, 32),
489490
"key2": getRandomBytes(b, 32),
490491
}
492+
action.Issuer = getRandomBytes(b, 32)
491493
return action
492494
}
495+
496+
func TestAction_GetIssuer(t *testing.T) {
497+
issuerId := []byte("issuer")
498+
action := &Action{
499+
Issuer: issuerId,
500+
}
501+
issuer := action.GetIssuer()
502+
assert.True(t, issuer.Equal(issuerId), "unexpected issuer id in Action")
503+
}

token/core/zkatdlog/nogh/v1/validator/validator_transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TransferSignatureValidate(ctx *Context) error {
6565
}
6666

6767
if isRedeem {
68-
ctx.Logger.Infof("action is a redeem, verify the signature of the issuer")
68+
ctx.Logger.Debugf("action is a redeem, verify the signature of the issuer")
6969

7070
issuer := ctx.TransferAction.GetIssuer()
7171
if issuer == nil {

token/driver/request_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func TestTokenRequestMetadataSerialization(t *testing.T) {
126126
[]byte("extra_signer1"),
127127
[]byte("extra_signer2"),
128128
},
129+
Issuer: Identity([]byte("issuer")),
129130
},
130131
},
131132
Application: map[string][]byte{

token/services/ttx/transfer_opts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const (
1818
IssuerFSCIdentityKey = "IssuerFSCIdentityKey"
1919
)
2020

21+
// WithFSCIssuerIdentity takes an issuer's node Identity
22+
// and sets the appropriate attribute in a TransferOptions struct
2123
func WithFSCIssuerIdentity(issuerFSCIdentity view.Identity) token.TransferOption {
2224
return func(options *token.TransferOptions) error {
2325
if options.Attributes == nil {
@@ -28,6 +30,8 @@ func WithFSCIssuerIdentity(issuerFSCIdentity view.Identity) token.TransferOption
2830
}
2931
}
3032

33+
// GetFSCIssuerIdentityFromOpts extracts an issuer's node identity
34+
// from the appropriate attribute in a given attribute map.
3135
func GetFSCIssuerIdentityFromOpts(attributes map[interface{}]interface{}) (view.Identity, error) {
3236
if attributes == nil {
3337
return nil, nil

0 commit comments

Comments
 (0)