-
Notifications
You must be signed in to change notification settings - Fork 501
/
memo_test.go
51 lines (43 loc) · 1.32 KB
/
memo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package txnbuild
import (
"testing"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
)
func TestMemoFromXDR(t *testing.T) {
// memo text
xdrMemo, err := xdr.NewMemo(xdr.MemoTypeMemoText, "abc123")
assert.NoError(t, err)
memo, err := memoFromXDR(xdrMemo)
if assert.NoError(t, err) {
assert.Equal(t, MemoText("abc123"), memo, "memo text should match")
}
// memo id
xdrMemo, err = xdr.NewMemo(xdr.MemoTypeMemoId, xdr.Uint64(1234))
assert.NoError(t, err)
memo, err = memoFromXDR(xdrMemo)
if assert.NoError(t, err) {
assert.Equal(t, MemoID(1234), memo, "memo id should match")
}
// memo hash
xdrMemo, err = xdr.NewMemo(xdr.MemoTypeMemoHash, xdr.Hash([32]byte{0x10}))
assert.NoError(t, err)
memo, err = memoFromXDR(xdrMemo)
if assert.NoError(t, err) {
assert.Equal(t, MemoHash([32]byte{0x10}), memo, "memo hash should match")
}
// memo return
xdrMemo, err = xdr.NewMemo(xdr.MemoTypeMemoReturn, xdr.Hash([32]byte{0x01}))
assert.NoError(t, err)
memo, err = memoFromXDR(xdrMemo)
if assert.NoError(t, err) {
assert.Equal(t, MemoReturn([32]byte{0x01}), memo, "memo return should match")
}
// memo none
xdrMemo, err = xdr.NewMemo(xdr.MemoTypeMemoNone, "")
assert.NoError(t, err)
memo, err = memoFromXDR(xdrMemo)
if assert.NoError(t, err) {
assert.Equal(t, nil, memo, "memo should be nil")
}
}