keycard-go/apdu/response_test.go

35 lines
891 B
Go
Raw Normal View History

2018-09-14 11:30:16 +00:00
package apdu
import (
"testing"
2018-09-27 09:23:12 +00:00
"github.com/status-im/status-go/smartcard/hexutils"
2018-09-14 11:30:16 +00:00
"github.com/stretchr/testify/assert"
)
func TestParseResponse(t *testing.T) {
2018-09-27 09:23:12 +00:00
raw := hexutils.HexToBytes("000002650183039536622002003b5e508f751c0af3016e3fbc23d3a69000")
2018-09-14 11:30:16 +00:00
resp, err := ParseResponse(raw)
assert.NoError(t, err)
assert.Equal(t, uint8(0x90), resp.Sw1)
assert.Equal(t, uint8(0x00), resp.Sw2)
assert.Equal(t, uint16(0x9000), resp.Sw)
expected := "000002650183039536622002003B5E508F751C0AF3016E3FBC23D3A6"
2018-09-27 09:23:12 +00:00
assert.Equal(t, expected, hexutils.BytesToHex(resp.Data))
2018-09-14 11:30:16 +00:00
}
func TestParseResponse_BadData(t *testing.T) {
2018-09-27 09:23:12 +00:00
raw := hexutils.HexToBytes("")
2018-09-14 11:30:16 +00:00
_, err := ParseResponse(raw)
assert.Equal(t, ErrBadRawResponse, err)
}
2018-09-25 15:48:21 +00:00
func TestResp_IsOK(t *testing.T) {
2018-09-27 09:23:12 +00:00
raw := hexutils.HexToBytes("01029000")
2018-09-25 15:48:21 +00:00
resp, err := ParseResponse(raw)
assert.NoError(t, err)
assert.True(t, resp.IsOK())
}