keycard-go/apdu/command_test.go

30 lines
710 B
Go
Raw Normal View History

2018-09-14 11:30:16 +00:00
package apdu
import (
"testing"
2019-03-01 17:44:07 +00:00
"github.com/status-im/keycard-go/hexutils"
2018-09-14 11:30:16 +00: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 09:23:12 +00:00
data := hexutils.HexToBytes("84762336c5187fe8")
2018-09-14 11:30:16 +00:00
cmd := NewCommand(cla, ins, p1, p2, data)
2018-09-27 16:01:09 +00:00
expected := "80 50 01 02 08 84 76 23 36 C5 18 7F E8"
result, err := cmd.Serialize()
2018-09-14 11:30:16 +00:00
assert.NoError(t, err)
2018-09-27 09:23:12 +00:00
assert.Equal(t, expected, hexutils.BytesToHexWithSpaces(result))
2018-09-27 16:01:09 +00:00
2018-09-28 09:25:08 +00:00
cmd.SetLe(uint8(0x77))
2018-09-27 16:01:09 +00: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 11:30:16 +00:00
}