OSDN Git Service

fix conflict
[bytom/vapor.git] / protocol / validation / test / tx_ugly_test.go
index 7243450..b988f94 100644 (file)
@@ -8,7 +8,8 @@ import (
        "github.com/vapor/account"
        "github.com/vapor/blockchain/signers"
        "github.com/vapor/consensus"
-       "github.com/vapor/crypto/ed25519/chainkd"
+       "github.com/vapor/crypto/csp"
+       edchainkd "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/protocol/validation"
@@ -628,7 +629,7 @@ type signingInst struct {
 
 func mockCtrlProgram(txData types.TxData, insts []*signingInst) {
        for i, input := range txData.Inputs {
-               _, xPubs := mustGetRootKeys(insts[i].rootPrvKeys)
+               _, xPubs := mustGetEdRootKeys(insts[i].rootPrvKeys)
 
                switch inp := input.TypedInput.(type) {
                case *types.SpendInput:
@@ -659,7 +660,7 @@ func mockSignTx(tx *types.Tx, insts []*signingInst) {
                                panic(err)
                        }
 
-                       xPrvs, xPubs := mustGetRootKeys(inst.rootPrvKeys)
+                       xPrvs, xPubs := mustGetEdRootKeys(inst.rootPrvKeys)
                        for _, xPrv := range xPrvs {
                                childPrv := xPrv.Derive(path)
                                sigHashBytes := tx.SigHash(uint32(i)).Byte32()
@@ -671,8 +672,8 @@ func mockSignTx(tx *types.Tx, insts []*signingInst) {
                                derivePK := childPrv.XPub()
                                arguments = append(arguments, derivePK.PublicKey())
                        } else {
-                               derivedXPubs := chainkd.DeriveXPubs(xPubs, path)
-                               derivedPKs := chainkd.XPubKeys(derivedXPubs)
+                               derivedXPubs := csp.DeriveXPubs(xPubs, path)
+                               derivedPKs := csp.XPubKeys(derivedXPubs)
                                script, err := vmutil.P2SPMultiSigProgram(derivedPKs, inst.quorum)
                                if err != nil {
                                        panic(err)
@@ -685,9 +686,10 @@ func mockSignTx(tx *types.Tx, insts []*signingInst) {
        }
 }
 
-func mustGetRootKeys(prvs []string) ([]chainkd.XPrv, []chainkd.XPub) {
-       xPubs := make([]chainkd.XPub, len(prvs))
-       xPrvs := make([]chainkd.XPrv, len(prvs))
+// must get ed25519 test keys
+func mustGetEdRootKeys(prvs []string) ([]edchainkd.XPrv, []edchainkd.XPub) {
+       xPubs := make([]edchainkd.XPub, len(prvs))
+       xPrvs := make([]edchainkd.XPrv, len(prvs))
        for i, xPrv := range prvs {
                xPrvBytes, err := hex.DecodeString(xPrv)
                if err != nil {
@@ -700,8 +702,30 @@ func mustGetRootKeys(prvs []string) ([]chainkd.XPrv, []chainkd.XPub) {
 
                var dest [64]byte
                copy(dest[:], xPrv)
-               xPrvs[i] = chainkd.XPrv(dest)
+               xPrvs[i] = edchainkd.XPrv(dest)
                xPubs[i] = xPrvs[i].XPub()
        }
        return xPrvs, xPubs
 }
+
+// TODO: must get sm2 test keys
+// func mustGetEdRootKeys(prvs []string) ([]edchainkd.XPrv, []edchainkd.XPub) {
+//     xPubs := make([]edchainkd.XPub, len(prvs))
+//     xPrvs := make([]edchainkd.XPrv, len(prvs))
+//     for i, xPrv := range prvs {
+//             xPrvBytes, err := hex.DecodeString(xPrv)
+//             if err != nil {
+//                     panic(err)
+//             }
+
+//             if len(xPrvBytes) != 64 {
+//                     panic("the size of xPrv must 64")
+//             }
+
+//             var dest [64]byte
+//             copy(dest[:], xPrv)
+//             xPrvs[i] = edchainkd.XPrv(dest)
+//             xPubs[i] = xPrvs[i].XPub()
+//     }
+//     return xPrvs, xPubs
+// }