-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprogram_test.go
38 lines (31 loc) · 933 Bytes
/
program_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
package memo
import (
"crypto/ed25519"
"testing"
"github.com/code-payments/code-server/pkg/solana"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestInstruction(t *testing.T) {
i := Instruction("hello, world!")
assert.Equal(t, ProgramKey, i.Program)
assert.Empty(t, i.Accounts)
assert.Equal(t, "hello, world!", string(i.Data))
}
func TestDecompile(t *testing.T) {
tx := solana.NewTransaction(
make([]byte, 32),
Instruction("hello, world"),
)
i, err := DecompileMemo(tx.Message, 0)
assert.NoError(t, err)
assert.Equal(t, "hello, world", string(i.Data))
_, err = DecompileMemo(tx.Message, 1)
assert.Error(t, err)
assert.Contains(t, err.Error(), "instruction doesn't exist")
tx.Message.Accounts[1], _, err = ed25519.GenerateKey(nil)
require.NoError(t, err)
_, err = DecompileMemo(tx.Message, 0)
assert.Error(t, err)
assert.Equal(t, solana.ErrIncorrectProgram, err)
}