Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Adding test for ammend commission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed Jul 21, 2020
1 parent c43f0a7 commit 271361e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
50 changes: 48 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func Test_UserGetVersion(t *testing.T) {

assert.Equal(t, uint8(0x0), version.AppMode, "TESTING MODE ENABLED!!")
assert.Equal(t, uint8(0x0), version.Major, "Wrong Major version")
assert.Equal(t, uint8(0xd), version.Minor, "Wrong Minor version")
}

func Test_UserGetPublicKey(t *testing.T) {
Expand Down Expand Up @@ -204,6 +203,17 @@ func Test_Sign(t *testing.T) {

path := []uint32{44, 474, 0, 0, 5}

// Verify Signature
pubKey, err := app.GetPublicKeyEd25519(path)
if err != nil {
t.Fatalf("Detected error, err: %s\n", err.Error())
}

if err != nil {
t.Fatalf("[GetPK] Error: " + err.Error())
return
}

message := getDummyTx()

println(coinContext)
Expand All @@ -214,6 +224,32 @@ func Test_Sign(t *testing.T) {
t.Fatalf("[Sign] Error: %s\n", err.Error())
}

message = append([]byte(coinContext), message...)
hash := sha512.Sum512_256(message)

verified := ed25519.Verify(pubKey, hash[:], signature)
if !verified {
t.Fatalf("[VerifySig] Error verifying signature")
return
}
}

func getDummyTx_Issue1() []byte {
base64tx := "pGNmZWWiY2dhcwBmYW1vdW50QGRib2R5oWlhbWVuZG1lbnSiZXJhdGVzgaJkcmF0ZUMBhqBlc3RhcnQZA+hmYm91bmRzgaNlc3RhcnQZA+hocmF0ZV9tYXhDAYagaHJhdGVfbWluQwGGoGVub25jZQBmbWV0aG9keB9zdGFraW5nLkFtZW5kQ29tbWlzc2lvblNjaGVkdWxl"
tx, _ := base64.StdEncoding.DecodeString(base64tx)
println(hex.EncodeToString(tx))
return tx
}

func Test_Sign_issue1(t *testing.T) {
app, err := FindLedgerOasisApp()
if err != nil {
t.Fatalf(err.Error())
}
defer app.Close()

path := []uint32{44, 474, 0, 0, 5}

// Verify Signature
pubKey, err := app.GetPublicKeyEd25519(path)
if err != nil {
Expand All @@ -225,8 +261,18 @@ func Test_Sign(t *testing.T) {
return
}

message := getDummyTx_Issue1()

println(coinContext)
println(hex.EncodeToString(message))

signature, err := app.SignEd25519(path, []byte(coinContext), message)
if err != nil {
t.Fatalf("[Sign] Error: %s\n", err.Error())
}

message = append([]byte(coinContext), message...)
hash := sha512.Sum512(message)
hash := sha512.Sum512_256(message)

verified := ed25519.Verify(pubKey, hash[:], signature)
if !verified {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.13
require (
github.com/oasisprotocol/oasis-core/go v0.0.0-20200623153002-9e61aea5195b
github.com/stretchr/testify v1.6.1
github.com/zondax/ledger-go v0.12.0
github.com/zondax/ledger-go v0.12.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,8 @@ github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8=
github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/ledger-go v0.11.0 h1:EEqUh6eaZucWAaGo87G7sJiqRNJpzBZr+I9PpGgjjPg=
github.com/zondax/ledger-go v0.11.0/go.mod h1:NI6JDs8VWwgh+9Bf1vPZMm9Xufp2Q7Iwm2IzxJWzmus=
github.com/zondax/ledger-go v0.12.0 h1:25GPOWW+Hg0NT6PNT5pbXmzwZ6r3W1IJLiLamoGJBnI=
github.com/zondax/ledger-go v0.12.0/go.mod h1:KatxXrVDzgWwbssUWsF5+cOJHXPvzQ09YSlzGNuhOEo=
github.com/zondax/ledger-go v0.12.1 h1:hYRcyznPRJp+5mzF2sazTLP2nGvGjYDD2VzhHhFomLU=
github.com/zondax/ledger-go v0.12.1/go.mod h1:KatxXrVDzgWwbssUWsF5+cOJHXPvzQ09YSlzGNuhOEo=
github.com/zondax/ledger-oasis-go v0.3.0/go.mod h1:czCs1jEu/4KYz3mYgALCedjgKxaFygAQxJ1di+3hHoI=
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec/go.mod h1:BZ1RAoRPbCxum9Grlv5aeksu2H8BiKehBYooU2LFiOQ=
gitlab.com/yawning/dynlib.git v0.0.0-20200603163025-35fe007b0761/go.mod h1:U41r+zgpFRTlkSzMhBjUqbupvVBafgokFFkKn0j+874=
Expand Down

0 comments on commit 271361e

Please sign in to comment.