-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestutil.go
87 lines (67 loc) · 2.76 KB
/
testutil.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
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
package async_sequencer
import (
"context"
"errors"
"github.com/code-payments/code-server/pkg/solana"
"github.com/code-payments/code-server/pkg/solana/memo"
"github.com/code-payments/code-server/pkg/code/common"
"github.com/code-payments/code-server/pkg/code/data/fulfillment"
"github.com/code-payments/code-server/pkg/code/data/transaction"
transaction_util "github.com/code-payments/code-server/pkg/code/transaction"
)
type mockScheduler struct {
shouldSchedule bool
}
func (s *mockScheduler) CanSubmitToBlockchain(_ context.Context, _ *fulfillment.Record) (bool, error) {
return s.shouldSchedule, nil
}
type mockFulfillmentHandler struct {
isScheduled bool
supportsOnDemandTxnCreation bool
isRevoked bool
isNonceUsedWhenRevoked bool
isRecoveredFromFailure bool
successCallbackExecuted bool
failureCallbackExecuted bool
}
func (h *mockFulfillmentHandler) CanSubmitToBlockchain(ctx context.Context, fulfillmentRecord *fulfillment.Record) (scheduled bool, err error) {
return h.isScheduled, nil
}
func (h *mockFulfillmentHandler) SupportsOnDemandTransactions() bool {
return h.supportsOnDemandTxnCreation
}
func (h *mockFulfillmentHandler) MakeOnDemandTransaction(ctx context.Context, fulfillmentRecord *fulfillment.Record, selectedNonce *transaction_util.SelectedNonce) (*solana.Transaction, error) {
if !h.supportsOnDemandTxnCreation {
return nil, errors.New("not supported")
}
txn := solana.NewTransaction(common.GetSubsidizer().PublicKey().ToBytes(), memo.Instruction(selectedNonce.Account.PublicKey().ToBase58()))
txn.Sign(common.GetSubsidizer().PrivateKey().ToBytes())
return &txn, nil
}
func (h *mockFulfillmentHandler) OnSuccess(ctx context.Context, fulfillmentRecord *fulfillment.Record, transactionRecord *transaction.Record) error {
h.successCallbackExecuted = true
return nil
}
func (h *mockFulfillmentHandler) OnFailure(ctx context.Context, fulfillmentRecord *fulfillment.Record, transactionRecord *transaction.Record) (recovered bool, err error) {
h.failureCallbackExecuted = true
return h.isRecoveredFromFailure, nil
}
func (h *mockFulfillmentHandler) IsRevoked(ctx context.Context, fulfillmentRecord *fulfillment.Record) (revoked bool, nonceUsed bool, err error) {
return h.isRevoked, h.isNonceUsedWhenRevoked, nil
}
type mockActionHandler struct {
callbackExecuted bool
reportedFulfillmentState fulfillment.State
}
func (h *mockActionHandler) OnFulfillmentStateChange(ctx context.Context, fulfillmentRecord *fulfillment.Record, newState fulfillment.State) error {
h.callbackExecuted = true
h.reportedFulfillmentState = newState
return nil
}
type mockIntentHandler struct {
callbackExecuted bool
}
func (h *mockIntentHandler) OnActionUpdated(ctx context.Context, intentId string) error {
h.callbackExecuted = true
return nil
}