keycard-go/apdu/command_test.go

30 lines
710 B
Go
Raw Normal View History

2018-09-14 13:30:16 +02:00
package apdu
import (
"testing"
2019-03-01 18:44:07 +01:00
"github.com/status-im/keycard-go/hexutils"
2018-09-14 13:30:16 +02:00
"github.com/stretchr/testify/assert"
)
func TestNewCommand(t *testing.T) {
var cla uint8 = 0x80
var ins uint8 = 0x50
var p1 uint8 = 1
var p2 uint8 = 2
2018-09-27 11:23:12 +02:00
data := hexutils.HexToBytes("84762336c5187fe8")
2018-09-14 13:30:16 +02:00
cmd := NewCommand(cla, ins, p1, p2, data)
2018-09-27 18:01:09 +02:00
expected := "80 50 01 02 08 84 76 23 36 C5 18 7F E8"
result, err := cmd.Serialize()
2018-09-14 13:30:16 +02:00
assert.NoError(t, err)
2018-09-27 11:23:12 +02:00
assert.Equal(t, expected, hexutils.BytesToHexWithSpaces(result))
2018-09-27 18:01:09 +02:00
2018-09-28 11:25:08 +02:00
cmd.SetLe(uint8(0x77))
2018-09-27 18:01:09 +02:00
expected = "80 50 01 02 08 84 76 23 36 C5 18 7F E8 77"
result, err = cmd.Serialize()
assert.NoError(t, err)
assert.Equal(t, expected, hexutils.BytesToHexWithSpaces(result))
2018-09-14 13:30:16 +02:00
}