Skip to content

Commit

Permalink
refactor test case
Browse files Browse the repository at this point in the history
  • Loading branch information
TATAUFO committed May 23, 2020
1 parent 94b89ac commit a167cb4
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 128 deletions.
23 changes: 18 additions & 5 deletions crypto/bitcoin/btc_crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestEEngine_EncryptKeyMS(t *testing.T) {

}

func TestMarshal(t *testing.T) {
func TestMarshalPrivateKey(t *testing.T) {
E := New()

privKey, _, err := E.GenKey(crypto.Signature2PublicKey)
Expand Down Expand Up @@ -461,6 +461,10 @@ func TestMarshal(t *testing.T) {
}
}

}
func TestMarshalPublicKey(t *testing.T) {
E := New()
size := 3
_, pubKey, err := E.GenKey(crypto.Signature2PublicKey)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -520,18 +524,21 @@ func TestMarshal(t *testing.T) {
t.Error("public key not match")
}
}

privKey, pubKey, err = E.GenKey(crypto.MultipleSignatures, size)
}
func TestMarshal(t *testing.T) {
E := New()
size := 3
privKey, pubKey, err := E.GenKey(crypto.MultipleSignatures, size)
if err != nil {
t.Error(err)
}

privKeyBytes, pubKeyBytes, err = E.Marshal(privKey, pubKey)
privKeyBytes, pubKeyBytes, err := E.Marshal(privKey, pubKey)
if err != nil {
t.Error(err)
}

uPrivKey, uPubKey, err = E.Unmarshal(privKeyBytes, pubKeyBytes)
uPrivKey, uPubKey, err := E.Unmarshal(privKeyBytes, pubKeyBytes)
if err != nil {
t.Error(err)
}
Expand All @@ -552,4 +559,10 @@ func TestMarshal(t *testing.T) {
}
}

for i := 0; i < size; i++ {
if privKey.PriKey.([]interface{})[i].(*btc.PrivateKey).D.Cmp(uPrivKey.PriKey.([]interface{})[i].(*btc.PrivateKey).D) != 0 {
t.Error("private key not match")
}
}

}
21 changes: 17 additions & 4 deletions crypto/ethereum/eth_crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestEEngine_EncryptKeyMS(t *testing.T) {

}

func TestMarshal(t *testing.T) {
func TestMarshalPrivateKey(t *testing.T) {
E := New()

privKey, _, err := E.GenKey(crypto.Signature2PublicKey)
Expand Down Expand Up @@ -454,7 +454,11 @@ func TestMarshal(t *testing.T) {
t.Error("private key not match")
}
}
}

func TestMarshalPublicKey(t *testing.T) {
E := New()
size := 3
_, pubKey, err := E.GenKey(crypto.Signature2PublicKey)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -514,18 +518,22 @@ func TestMarshal(t *testing.T) {
t.Error("public key not match")
}
}
}

privKey, pubKey, err = E.GenKey(crypto.MultipleSignatures, size)
func TestMarshal(t *testing.T) {
E := New()
size := 3
privKey, pubKey, err := E.GenKey(crypto.MultipleSignatures, size)
if err != nil {
t.Error(err)
}

privKeyBytes, pubKeyBytes, err = E.Marshal(privKey, pubKey)
privKeyBytes, pubKeyBytes, err := E.Marshal(privKey, pubKey)
if err != nil {
t.Error(err)
}

uPrivKey, uPubKey, err = E.Unmarshal(privKeyBytes, pubKeyBytes)
uPrivKey, uPubKey, err := E.Unmarshal(privKeyBytes, pubKeyBytes)
if err != nil {
t.Error(err)
}
Expand All @@ -545,5 +553,10 @@ func TestMarshal(t *testing.T) {
t.Error("public key not match")
}
}
for i := 0; i < size; i++ {
if privKey.PriKey.([]interface{})[i].(*ecdsa.PrivateKey).D.Cmp(uPrivKey.PriKey.([]interface{})[i].(*ecdsa.PrivateKey).D) != 0 {
t.Error("private key not match")
}
}

}
Loading

0 comments on commit a167cb4

Please sign in to comment.