Skip to content

Commit 244b0cf

Browse files
committed
Add e2e/tests/ton/set_root.go (wip)
1 parent b636c83 commit 244b0cf

File tree

6 files changed

+354
-49
lines changed

6 files changed

+354
-49
lines changed

e2e/tests/runner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ func TestTONSuite(t *testing.T) {
4646
// suite.Run(t, new(tone2e.TimelockInspectionTestSuite))
4747
suite.Run(t, new(tone2e.SigningTestSuite))
4848
suite.Run(t, new(tone2e.SetConfigTestSuite))
49+
suite.Run(t, new(tone2e.SetRootTestSuite))
4950
}

e2e/tests/ton/common.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/smartcontractkit/chainlink-ton/pkg/ton/tvm"
1010
"github.com/xssnick/tonutils-go/address"
11+
"github.com/xssnick/tonutils-go/ton/wallet"
1112

1213
"github.com/smartcontractkit/chainlink-ton/pkg/bindings/mcms/mcms"
1314
"github.com/smartcontractkit/chainlink-ton/pkg/ccip/bindings/common"
@@ -29,6 +30,14 @@ func must[E any](out E, err error) E {
2930
return out
3031
}
3132

33+
func makeRandomTestWallet(api wallet.TonAPI, networkGlobalID int32) (*wallet.Wallet, error) {
34+
v5r1Config := wallet.ConfigV5R1Final{
35+
NetworkGlobalID: networkGlobalID,
36+
Workchain: 0,
37+
}
38+
return wallet.FromSeed(api, wallet.NewSeed(), v5r1Config)
39+
}
40+
3241
// TODO: duplicated utils with unit tests [END]
3342

3443
func MCMSContractDataFrom(owner *address.Address, chainId int64) mcms.Data {
@@ -39,7 +48,7 @@ func MCMSContractDataFrom(owner *address.Address, chainId int64) mcms.Data {
3948
PendingOwner: nil,
4049
},
4150
Oracle: tvm.ZeroAddress,
42-
Signers: must(tvm.MakeDict(map[*big.Int]mcms.Signer{}, tvm.KeyUINT256)),
51+
Signers: must(tvm.MakeDict(map[*big.Int]mcms.Signer{}, 160)), // TODO: tvm.KeyUINT160
4352
Config: mcms.Config{
4453
Signers: must(tvm.MakeDictFrom([]mcms.Signer{}, tvm.KeyUINT8)),
4554
GroupQuorums: must(tvm.MakeDictFrom([]mcms.GroupQuorum{}, tvm.KeyUINT8)),

e2e/tests/ton/set_config.go

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import (
66
"math/big"
77
"os"
88
"path/filepath"
9-
"slices"
109
"strings"
1110
"time"
1211

1312
"github.com/ethereum/go-ethereum/common"
14-
"github.com/ethereum/go-ethereum/crypto"
1513

1614
"github.com/stretchr/testify/suite"
1715

@@ -26,11 +24,12 @@ import (
2624
"github.com/smartcontractkit/chainlink-ton/pkg/ton/wrappers"
2725

2826
e2e "github.com/smartcontractkit/mcms/e2e/tests"
27+
"github.com/smartcontractkit/mcms/internal/testutils"
2928
"github.com/smartcontractkit/mcms/sdk"
3029
"github.com/smartcontractkit/mcms/types"
3130

3231
commonton "github.com/smartcontractkit/chainlink-ton/pkg/ccip/bindings/common"
33-
tonmcms "github.com/smartcontractkit/mcms/sdk/ton"
32+
mcmston "github.com/smartcontractkit/mcms/sdk/ton"
3433
)
3534

3635
// SetConfigTestSuite tests signing a proposal and converting back to a file
@@ -77,7 +76,7 @@ func (t *SetConfigTestSuite) deployMCMSContract() {
7776
PendingOwner: nil,
7877
},
7978
Oracle: tvm.ZeroAddress,
80-
Signers: must(tvm.MakeDict(map[*big.Int]mcms.Signer{}, tvm.KeyUINT256)),
79+
Signers: must(tvm.MakeDict(map[*big.Int]mcms.Signer{}, 160)), // TODO: tvm.KeyUINT160
8180
Config: mcms.Config{
8281
Signers: must(tvm.MakeDictFrom([]mcms.Signer{}, tvm.KeyUINT8)),
8382
GroupQuorums: must(tvm.MakeDictFrom([]mcms.GroupQuorum{}, tvm.KeyUINT8)),
@@ -123,20 +122,13 @@ func (t *SetConfigTestSuite) deployMCMSContract() {
123122

124123
func (t *SetConfigTestSuite) Test_TON_SetConfigInspect() {
125124
// Signers in each group need to be sorted alphabetically
126-
signers := [30]common.Address{}
127-
for i := range signers {
128-
key, _ := crypto.GenerateKey()
129-
signers[i] = crypto.PubkeyToAddress(key.PublicKey)
130-
}
131-
slices.SortFunc(signers[:], func(a, b common.Address) int {
132-
return strings.Compare(strings.ToLower(a.Hex()), strings.ToLower(b.Hex()))
133-
})
125+
signers := testutils.MakeNewECDSASigners(30)
134126

135127
amount := tlb.MustFromTON("0.3")
136-
configurerTON, err := tonmcms.NewConfigurer(t.wallet, amount)
128+
configurerTON, err := mcmston.NewConfigurer(t.wallet, amount)
137129
t.Require().NoError(err)
138130

139-
inspectorTON := tonmcms.NewInspector(t.TonClient, tonmcms.NewConfigTransformer())
131+
inspectorTON := mcmston.NewInspector(t.TonClient, mcmston.NewConfigTransformer())
140132
t.Require().NoError(err)
141133

142134
tests := []struct {
@@ -151,26 +143,26 @@ func (t *SetConfigTestSuite) Test_TON_SetConfigInspect() {
151143
config: types.Config{
152144
Quorum: 2,
153145
Signers: []common.Address{
154-
signers[0],
155-
signers[1],
156-
signers[2],
146+
signers[0].Address(),
147+
signers[1].Address(),
148+
signers[2].Address(),
157149
},
158150
GroupSigners: []types.Config{
159151
{
160152
Quorum: 4,
161153
Signers: []common.Address{
162-
signers[3],
163-
signers[4],
164-
signers[5],
165-
signers[6],
166-
signers[7],
154+
signers[3].Address(),
155+
signers[4].Address(),
156+
signers[5].Address(),
157+
signers[6].Address(),
158+
signers[7].Address(),
167159
},
168160
GroupSigners: []types.Config{
169161
{
170162
Quorum: 1,
171163
Signers: []common.Address{
172-
signers[8],
173-
signers[9],
164+
signers[8].Address(),
165+
signers[9].Address(),
174166
},
175167
GroupSigners: []types.Config{},
176168
},
@@ -179,10 +171,10 @@ func (t *SetConfigTestSuite) Test_TON_SetConfigInspect() {
179171
{
180172
Quorum: 3,
181173
Signers: []common.Address{
182-
signers[10],
183-
signers[11],
184-
signers[12],
185-
signers[13],
174+
signers[10].Address(),
175+
signers[11].Address(),
176+
signers[12].Address(),
177+
signers[13].Address(),
186178
},
187179
GroupSigners: []types.Config{},
188180
},
@@ -196,17 +188,17 @@ func (t *SetConfigTestSuite) Test_TON_SetConfigInspect() {
196188
config: types.Config{
197189
Quorum: 1,
198190
Signers: []common.Address{
199-
signers[14],
200-
signers[15],
191+
signers[14].Address(),
192+
signers[15].Address(),
201193
},
202194
GroupSigners: []types.Config{
203195
{
204196
Quorum: 2,
205197
Signers: []common.Address{
206-
signers[16],
207-
signers[17],
208-
signers[18],
209-
signers[19],
198+
signers[16].Address(),
199+
signers[17].Address(),
200+
signers[18].Address(),
201+
signers[19].Address(),
210202
},
211203
GroupSigners: []types.Config{},
212204
},
@@ -224,26 +216,26 @@ func (t *SetConfigTestSuite) Test_TON_SetConfigInspect() {
224216
{
225217
Quorum: 2,
226218
Signers: []common.Address{
227-
signers[20],
228-
signers[21],
229-
signers[22],
230-
signers[23],
219+
signers[20].Address(),
220+
signers[21].Address(),
221+
signers[22].Address(),
222+
signers[23].Address(),
231223
},
232224
GroupSigners: []types.Config{},
233225
}, {
234226
Quorum: 2,
235227
Signers: []common.Address{
236-
signers[24],
237-
signers[25],
238-
signers[26],
239-
signers[27],
228+
signers[24].Address(),
229+
signers[25].Address(),
230+
signers[26].Address(),
231+
signers[27].Address(),
240232
},
241233
GroupSigners: []types.Config{},
242234
}, {
243235
Quorum: 1,
244236
Signers: []common.Address{
245-
signers[28],
246-
signers[29],
237+
signers[28].Address(),
238+
signers[29].Address(),
247239
},
248240
GroupSigners: []types.Config{},
249241
},

0 commit comments

Comments
 (0)