@@ -10,6 +10,7 @@ import (
1010 "testing"
1111
1212 math "github.com/IBM/mathlib"
13+ fabtokenv1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/actions"
1314 v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
1415 token2 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/token"
1516 "github.com/hyperledger-labs/fabric-token-sdk/token/services/tokens"
@@ -470,3 +471,104 @@ func TestMetadataDeserialize(t *testing.T) {
470471 })
471472 }
472473}
474+
475+ func TestUpgradeWitnessValidate (t * testing.T ) {
476+ tests := []struct {
477+ name string
478+ token func () (* token2.UpgradeWitness , error )
479+ wantErr bool
480+ expectedError string
481+ }{
482+ {
483+ name : "missing FabToken" ,
484+ token : func () (* token2.UpgradeWitness , error ) {
485+ return & token2.UpgradeWitness {}, nil
486+ },
487+ wantErr : true ,
488+ expectedError : "missing FabToken" ,
489+ },
490+ {
491+ name : "missing FabToken.Owner" ,
492+ token : func () (* token2.UpgradeWitness , error ) {
493+ return & token2.UpgradeWitness {
494+ FabToken : & fabtokenv1.Output {},
495+ BlindingFactor : nil ,
496+ }, nil
497+ },
498+ wantErr : true ,
499+ expectedError : "missing FabToken.Owner" ,
500+ },
501+ {
502+ name : "missing FabToken.Type" ,
503+ token : func () (* token2.UpgradeWitness , error ) {
504+ return & token2.UpgradeWitness {
505+ FabToken : & fabtokenv1.Output {
506+ Owner : []byte ("owner" ),
507+ Type : "" ,
508+ Quantity : "" ,
509+ },
510+ BlindingFactor : nil ,
511+ }, nil
512+ },
513+ wantErr : true ,
514+ expectedError : "missing FabToken.Type" ,
515+ },
516+ {
517+ name : "missing FabToken.Quantity" ,
518+ token : func () (* token2.UpgradeWitness , error ) {
519+ return & token2.UpgradeWitness {
520+ FabToken : & fabtokenv1.Output {
521+ Owner : []byte ("owner" ),
522+ Type : "token type" ,
523+ Quantity : "" ,
524+ },
525+ BlindingFactor : nil ,
526+ }, nil
527+ },
528+ wantErr : true ,
529+ expectedError : "missing FabToken.Quantity" ,
530+ },
531+ {
532+ name : "missing BlindingFactor" ,
533+ token : func () (* token2.UpgradeWitness , error ) {
534+ return & token2.UpgradeWitness {
535+ FabToken : & fabtokenv1.Output {
536+ Owner : []byte ("owner" ),
537+ Type : "token type" ,
538+ Quantity : "quantity" ,
539+ },
540+ BlindingFactor : nil ,
541+ }, nil
542+ },
543+ wantErr : true ,
544+ expectedError : "missing BlindingFactor" ,
545+ },
546+ {
547+ name : "success" ,
548+ token : func () (* token2.UpgradeWitness , error ) {
549+ return & token2.UpgradeWitness {
550+ FabToken : & fabtokenv1.Output {
551+ Owner : []byte ("owner" ),
552+ Type : "token type" ,
553+ Quantity : "quantity" ,
554+ },
555+ BlindingFactor : & math.Zr {},
556+ }, nil
557+ },
558+ wantErr : false ,
559+ },
560+ }
561+ for _ , tt := range tests {
562+ t .Run (tt .name , func (t * testing.T ) {
563+ tok , err := tt .token ()
564+ assert .NoError (t , err )
565+ err = tok .Validate ()
566+ if tt .wantErr {
567+ assert .Error (t , err )
568+ assert .EqualError (t , err , tt .expectedError )
569+ } else {
570+ assert .NoError (t , err )
571+ }
572+ })
573+ }
574+ }
0 commit comments