-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathencoding_test.go
More file actions
120 lines (91 loc) · 3.59 KB
/
Copy pathencoding_test.go
File metadata and controls
120 lines (91 loc) · 3.59 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package mcmsutils
import (
"os"
"path/filepath"
"testing"
mcmslib "github.com/smartcontractkit/mcms"
mcmstypes "github.com/smartcontractkit/mcms/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEncodeProposal(t *testing.T) {
t.Parallel()
// Decode a proposal from test data
proposalJSON, err := os.ReadFile(filepath.Join("testdata", "proposal.json"))
require.NoError(t, err, "Failed to read test data file")
proposal, err := DecodeProposal(string(proposalJSON))
require.NoError(t, err, "Failed to decode original proposal")
t.Run("successful encoding", func(t *testing.T) {
t.Parallel()
encodedJSON, err := EncodeProposal(proposal)
require.NoError(t, err)
assert.NotEmpty(t, encodedJSON)
assert.JSONEq(t, string(proposalJSON), encodedJSON)
})
}
func TestDecodeProposal(t *testing.T) {
t.Parallel()
// Read the test data file
proposalJSON, rerr := os.ReadFile(filepath.Join("testdata", "proposal.json"))
require.NoError(t, rerr, "Failed to read test data file")
t.Run("successful decoding", func(t *testing.T) {
t.Parallel()
var proposal *mcmslib.Proposal
proposal, err := DecodeProposal(string(proposalJSON))
require.NoError(t, err)
require.NotNil(t, proposal)
// Basic assertions since the we use mcmslib to decode the proposal
assert.Equal(t, "v1", proposal.Version)
assert.Equal(t, mcmstypes.ProposalKind("Proposal"), proposal.Kind)
require.Contains(t, proposal.ChainMetadata, mcmstypes.ChainSelector(3379446385462418246))
require.Len(t, proposal.Operations, 2)
})
t.Run("failed decoding", func(t *testing.T) {
t.Parallel()
_, err := DecodeProposal("invalid JSON")
require.Error(t, err)
})
}
func TestEncodeTimelockProposal(t *testing.T) {
t.Parallel()
// Decode a timelock proposal from test data
timelockJSON, err := os.ReadFile(filepath.Join("testdata", "timelock_proposal.json"))
require.NoError(t, err, "Failed to read timelock test data file")
timelockProposal, err := DecodeTimelockProposal(string(timelockJSON))
require.NoError(t, err, "Failed to decode original timelock proposal")
t.Run("successful encoding", func(t *testing.T) {
t.Parallel()
encodedJSON, err := EncodeTimelockProposal(timelockProposal)
require.NoError(t, err)
assert.NotEmpty(t, encodedJSON)
// Verify we can decode it back successfully (instead of strict JSON comparison)
decodedProposal, err := DecodeTimelockProposal(encodedJSON)
require.NoError(t, err)
require.NotNil(t, decodedProposal)
assert.JSONEq(t, string(timelockJSON), encodedJSON)
})
}
func TestDecodeTimelockProposal(t *testing.T) {
t.Parallel()
// Read the timelock test data file
timelockJSON, rerr := os.ReadFile(filepath.Join("testdata", "timelock_proposal.json"))
require.NoError(t, rerr, "Failed to read timelock test data file")
t.Run("successful decoding", func(t *testing.T) {
t.Parallel()
var timelockProposal *mcmslib.TimelockProposal
timelockProposal, err := DecodeTimelockProposal(string(timelockJSON))
require.NoError(t, err)
require.NotNil(t, timelockProposal)
// Basic assertions since the we use mcmslib to decode the proposal
assert.Equal(t, "v1", timelockProposal.Version)
assert.Equal(t, mcmstypes.ProposalKind("TimelockProposal"), timelockProposal.Kind)
assert.Equal(t, mcmstypes.TimelockActionSchedule, timelockProposal.Action)
assert.Contains(t, timelockProposal.ChainMetadata, mcmstypes.ChainSelector(16015286601757825753))
assert.Len(t, timelockProposal.Operations, 1)
})
t.Run("failed decoding", func(t *testing.T) {
t.Parallel()
_, err := DecodeTimelockProposal("invalid JSON")
require.Error(t, err)
})
}