Skip to content

Commit 01797f9

Browse files
committed
Add sdk/ton/executor_test.go
1 parent ef225fb commit 01797f9

File tree

6 files changed

+413
-24
lines changed

6 files changed

+413
-24
lines changed

sdk/ton/configurer_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/mock"
1313
"github.com/stretchr/testify/require"
14+
15+
"github.com/smartcontractkit/mcms/internal/testutils/chaintest"
16+
"github.com/smartcontractkit/mcms/types"
17+
1418
"github.com/xssnick/tonutils-go/tlb"
1519
"github.com/xssnick/tonutils-go/ton"
1620
"github.com/xssnick/tonutils-go/ton/wallet"
1721

18-
"github.com/smartcontractkit/mcms/internal/testutils/chaintest"
1922
tonmcms "github.com/smartcontractkit/mcms/sdk/ton"
2023
ton_mocks "github.com/smartcontractkit/mcms/sdk/ton/mocks"
21-
"github.com/smartcontractkit/mcms/types"
2224
)
2325

2426
// TestConfigurer_SetConfig tests the SetConfig method of the Configurer.
@@ -127,7 +129,7 @@ func TestConfigurer_SetConfig(t *testing.T) {
127129

128130
// Mock SendTransaction to return an error
129131
m.EXPECT().SendExternalMessageWaitTransaction(mock.Anything, mock.Anything).
130-
Return(&tlb.Transaction{Hash: []byte{1, 2, 3, 4, 15}}, &ton.BlockIDExt{}, []byte{}, errors.New("transaction failed"))
132+
Return(&tlb.Transaction{Hash: []byte{1, 2, 3, 4, 14}}, &ton.BlockIDExt{}, []byte{}, errors.New("transaction failed"))
131133
},
132134
want: "",
133135
wantErr: errors.New("transaction failed"),

sdk/ton/executor.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,25 @@ type executor struct {
3838
}
3939

4040
// NewExecutor creates a new Executor for TON chains
41-
func NewExecutor(encoder sdk.Encoder, client *ton.APIClient, wallet *wallet.Wallet, amount tlb.Coins) sdk.Executor {
41+
func NewExecutor(encoder sdk.Encoder, client ton.APIClientWrapped, wallet *wallet.Wallet, amount tlb.Coins) (sdk.Executor, error) {
42+
if encoder == nil {
43+
return nil, errors.New("failed to create sdk.Executor - encoder (sdk.Encoder) is nil")
44+
}
45+
46+
if client == nil {
47+
return nil, errors.New("failed to create sdk.Executor - client (ton.APIClientWrapped) is nil")
48+
}
49+
50+
if wallet == nil {
51+
return nil, errors.New("failed to create sdk.Executor - wallet (*wallet.Wallet) is nil")
52+
}
53+
4254
return &executor{
4355
Encoder: encoder,
4456
Inspector: NewInspector(client, NewConfigTransformer()),
4557
wallet: wallet,
4658
amount: amount,
47-
}
59+
}, nil
4860
}
4961

5062
func (e *executor) ExecuteOperation(
@@ -54,10 +66,6 @@ func (e *executor) ExecuteOperation(
5466
proof []common.Hash,
5567
op types.Operation,
5668
) (types.TransactionResult, error) {
57-
if e.Encoder == nil {
58-
return types.TransactionResult{}, errors.New("executor was created without an encoder")
59-
}
60-
6169
oe, ok := e.Encoder.(OperationEncoder[mcms.Op])
6270
if !ok {
6371
return types.TransactionResult{}, fmt.Errorf("failed to assert OperationEncoder")
@@ -127,16 +135,6 @@ func (e *executor) SetRoot(
127135
validUntil uint32,
128136
sortedSignatures []types.Signature,
129137
) (types.TransactionResult, error) {
130-
if e.Encoder == nil {
131-
return types.TransactionResult{}, errors.New("Executor was created without an encoder")
132-
}
133-
134-
// Map to Ton Address type
135-
dstAddr, err := address.ParseAddr(metadata.MCMAddress)
136-
if err != nil {
137-
return types.TransactionResult{}, fmt.Errorf("invalid timelock address: %w", err)
138-
}
139-
140138
rme, ok := e.Encoder.(RootMetadataEncoder[mcms.RootMetadata])
141139
if !ok {
142140
return types.TransactionResult{}, fmt.Errorf("failed to assert RootMetadataEncoder")
@@ -147,6 +145,12 @@ func (e *executor) SetRoot(
147145
return types.TransactionResult{}, fmt.Errorf("failed to convert to root metadata: %w", err)
148146
}
149147

148+
// Map to Ton Address type
149+
dstAddr, err := address.ParseAddr(metadata.MCMAddress)
150+
if err != nil {
151+
return types.TransactionResult{}, fmt.Errorf("invalid timelock address: %w", err)
152+
}
153+
150154
// Encode proofs
151155
pe, ok := e.Encoder.(ProofEncoder[mcms.Proof])
152156
if !ok {

0 commit comments

Comments
 (0)