@chainlink/cre-sdk 1.15.0 → 1.17.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +2 -62
  2. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1035 -0
  3. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
  4. package/dist/generated/capabilities/blockchain/evm/v1alpha/client_pb.js +1 -1
  5. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +2885 -15
  6. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +459 -7
  7. package/dist/generated/capabilities/networking/http/v1alpha/client_pb.js +1 -1
  8. package/dist/generated/sdk/v1alpha/sdk_pb.d.ts +505 -0
  9. package/dist/generated/sdk/v1alpha/sdk_pb.js +121 -15
  10. package/dist/generated/tools/generator/v1alpha/cre_metadata_pb.d.ts +30 -1
  11. package/dist/generated/tools/generator/v1alpha/cre_metadata_pb.js +20 -2
  12. package/dist/generated/workflows/v2/cre_info_pb.d.ts +123 -0
  13. package/dist/generated/workflows/v2/cre_info_pb.js +17 -0
  14. package/dist/generated/workflows/v2/workflow_key_pb.d.ts +55 -0
  15. package/dist/generated/workflows/v2/workflow_key_pb.js +17 -0
  16. package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +118 -0
  17. package/dist/generated/workflows/v2/workflow_user_metric_pb.js +41 -0
  18. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +63 -0
  19. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +247 -0
  20. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +14 -0
  21. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +95 -0
  22. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +69 -2
  23. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +403 -1
  24. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +5 -1
  25. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +22 -0
  26. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +4 -0
  27. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +12 -0
  28. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +11 -1
  29. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +12 -0
  30. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +2 -0
  31. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +2 -0
  32. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +2 -0
  33. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +2 -0
  34. package/dist/sdk/cre/index.d.ts +30 -15
  35. package/dist/sdk/cre/index.js +29 -14
  36. package/dist/sdk/impl/runtime-impl.d.ts +28 -1
  37. package/dist/sdk/impl/runtime-impl.js +52 -1
  38. package/dist/sdk/runtime.d.ts +23 -1
  39. package/dist/sdk/tee-constraints.d.ts +68 -0
  40. package/dist/sdk/tee-constraints.js +59 -0
  41. package/dist/sdk/test/evm-contract-mock.js +58 -60
  42. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
  43. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
  44. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +19 -1
  45. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +141 -1
  46. package/dist/sdk/test/generated/index.d.ts +1 -0
  47. package/dist/sdk/test/generated/index.js +1 -0
  48. package/dist/sdk/test/index.d.ts +0 -1
  49. package/dist/sdk/test/index.js +0 -1
  50. package/dist/sdk/testutils/index.d.ts +1 -1
  51. package/dist/sdk/testutils/index.js +1 -1
  52. package/dist/sdk/testutils/test-runtime.d.ts +17 -4
  53. package/dist/sdk/testutils/test-runtime.js +31 -5
  54. package/dist/sdk/testutils/test-writer.d.ts +7 -1
  55. package/dist/sdk/testutils/test-writer.js +13 -1
  56. package/dist/sdk/types/global.d.ts +8 -0
  57. package/dist/sdk/utils/capabilities/blockchain/{evm/evm-helpers.d.ts → blockchain-helpers.d.ts} +6 -7
  58. package/dist/sdk/utils/capabilities/blockchain/{evm/evm-helpers.js → blockchain-helpers.js} +8 -6
  59. package/dist/sdk/utils/hex-utils.d.ts +0 -6
  60. package/dist/sdk/utils/hex-utils.js +0 -8
  61. package/dist/sdk/utils/index.d.ts +1 -3
  62. package/dist/sdk/utils/index.js +1 -2
  63. package/dist/sdk/wasm/host-bindings.d.ts +4 -0
  64. package/dist/sdk/wasm/host-bindings.js +4 -0
  65. package/dist/sdk/wasm/runner.d.ts +10 -4
  66. package/dist/sdk/wasm/runner.js +86 -13
  67. package/dist/sdk/wasm/runtime.d.ts +4 -1
  68. package/dist/sdk/wasm/runtime.js +9 -1
  69. package/dist/sdk/workflow.d.ts +16 -7
  70. package/dist/sdk/workflow.js +10 -2
  71. package/dist/workflows/standard_tests/restrictions/test.ts +41 -0
  72. package/dist/workflows/standard_tests/tee_runtime/test.ts +29 -0
  73. package/package.json +3 -6
  74. package/scripts/src/generate-sdks.ts +6 -0
  75. package/dist/sdk/test/contract-mock-core.d.ts +0 -16
  76. package/dist/sdk/test/contract-mock-core.js +0 -21
  77. package/dist/sdk/test/solana-contract-mock.d.ts +0 -54
  78. package/dist/sdk/test/solana-contract-mock.js +0 -63
  79. package/dist/sdk/utils/capabilities/blockchain/report-helpers.d.ts +0 -19
  80. package/dist/sdk/utils/capabilities/blockchain/report-helpers.js +0 -16
  81. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.d.ts +0 -101
  82. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.js +0 -100
@@ -0,0 +1,111 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { AccountAPTBalanceReplySchema, AccountAPTBalanceRequestSchema, AccountTransactionsReplySchema, AccountTransactionsRequestSchema, TransactionByHashReplySchema, TransactionByHashRequestSchema, ViewReplySchema, ViewRequestSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../../../generated/capabilities/blockchain/aptos/v1alpha/client_pb';
4
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
+ /**
6
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
7
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
8
+ */
9
+ export class AptosMock {
10
+ static CAPABILITY_ID = 'aptos@1.0.0';
11
+ /** Set to define the return value for AccountAPTBalance. May return a plain object (AccountAPTBalanceReplyJson) or the message type. */
12
+ accountAPTBalance;
13
+ /** Set to define the return value for View. May return a plain object (ViewReplyJson) or the message type. */
14
+ view;
15
+ /** Set to define the return value for TransactionByHash. May return a plain object (TransactionByHashReplyJson) or the message type. */
16
+ transactionByHash;
17
+ /** Set to define the return value for AccountTransactions. May return a plain object (AccountTransactionsReplyJson) or the message type. */
18
+ accountTransactions;
19
+ /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
20
+ writeReport;
21
+ constructor(chainSelector) {
22
+ const self = this;
23
+ const qualifiedId = `aptos:ChainSelector:${chainSelector}@1.0.0`;
24
+ try {
25
+ registerTestCapability(qualifiedId, (req) => {
26
+ switch (req.method) {
27
+ case 'AccountAPTBalance': {
28
+ const input = anyUnpack(req.payload, AccountAPTBalanceRequestSchema);
29
+ const handler = self.accountAPTBalance;
30
+ if (typeof handler !== 'function')
31
+ throw new Error("AccountAPTBalance: no implementation provided; set the mock's accountAPTBalance property to define the return value.");
32
+ const raw = handler(input);
33
+ const output = raw && typeof raw.$typeName === 'string'
34
+ ? raw
35
+ : fromJson(AccountAPTBalanceReplySchema, raw);
36
+ return {
37
+ response: { case: 'payload', value: anyPack(AccountAPTBalanceReplySchema, output) },
38
+ };
39
+ }
40
+ case 'View': {
41
+ const input = anyUnpack(req.payload, ViewRequestSchema);
42
+ const handler = self.view;
43
+ if (typeof handler !== 'function')
44
+ throw new Error("View: no implementation provided; set the mock's view property to define the return value.");
45
+ const raw = handler(input);
46
+ const output = raw && typeof raw.$typeName === 'string'
47
+ ? raw
48
+ : fromJson(ViewReplySchema, raw);
49
+ return { response: { case: 'payload', value: anyPack(ViewReplySchema, output) } };
50
+ }
51
+ case 'TransactionByHash': {
52
+ const input = anyUnpack(req.payload, TransactionByHashRequestSchema);
53
+ const handler = self.transactionByHash;
54
+ if (typeof handler !== 'function')
55
+ throw new Error("TransactionByHash: no implementation provided; set the mock's transactionByHash property to define the return value.");
56
+ const raw = handler(input);
57
+ const output = raw && typeof raw.$typeName === 'string'
58
+ ? raw
59
+ : fromJson(TransactionByHashReplySchema, raw);
60
+ return {
61
+ response: { case: 'payload', value: anyPack(TransactionByHashReplySchema, output) },
62
+ };
63
+ }
64
+ case 'AccountTransactions': {
65
+ const input = anyUnpack(req.payload, AccountTransactionsRequestSchema);
66
+ const handler = self.accountTransactions;
67
+ if (typeof handler !== 'function')
68
+ throw new Error("AccountTransactions: no implementation provided; set the mock's accountTransactions property to define the return value.");
69
+ const raw = handler(input);
70
+ const output = raw && typeof raw.$typeName === 'string'
71
+ ? raw
72
+ : fromJson(AccountTransactionsReplySchema, raw);
73
+ return {
74
+ response: { case: 'payload', value: anyPack(AccountTransactionsReplySchema, output) },
75
+ };
76
+ }
77
+ case 'WriteReport': {
78
+ const input = anyUnpack(req.payload, WriteReportRequestSchema);
79
+ const handler = self.writeReport;
80
+ if (typeof handler !== 'function')
81
+ throw new Error("WriteReport: no implementation provided; set the mock's writeReport property to define the return value.");
82
+ const raw = handler(input);
83
+ const output = raw && typeof raw.$typeName === 'string'
84
+ ? raw
85
+ : fromJson(WriteReportReplySchema, raw);
86
+ return { response: { case: 'payload', value: anyPack(WriteReportReplySchema, output) } };
87
+ }
88
+ default:
89
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
90
+ }
91
+ });
92
+ }
93
+ catch {
94
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
95
+ }
96
+ }
97
+ /**
98
+ * Returns the mock instance for this capability and the specified tags.
99
+ * Multiple calls with the same tag values return the same instance.
100
+ * Must be called within the test framework's test() method.
101
+ */
102
+ static testInstance(chainSelector) {
103
+ const qualifiedId = `aptos:ChainSelector:${chainSelector}@1.0.0`;
104
+ let instance = __getTestMockInstance(qualifiedId);
105
+ if (!instance) {
106
+ instance = new AptosMock(chainSelector);
107
+ __setTestMockInstance(qualifiedId, instance);
108
+ }
109
+ return instance;
110
+ }
111
+ }
@@ -1,10 +1,28 @@
1
- import { type WriteReportReply, type WriteReportReplyJson, type WriteReportRequest } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
1
+ import { type GetAccountInfoWithOptsReply, type GetAccountInfoWithOptsReplyJson, type GetAccountInfoWithOptsRequest, type GetBalanceReply, type GetBalanceReplyJson, type GetBalanceRequest, type GetBlockReply, type GetBlockReplyJson, type GetBlockRequest, type GetFeeForMessageReply, type GetFeeForMessageReplyJson, type GetFeeForMessageRequest, type GetMultipleAccountsWithOptsReply, type GetMultipleAccountsWithOptsReplyJson, type GetMultipleAccountsWithOptsRequest, type GetProgramAccountsReply, type GetProgramAccountsReplyJson, type GetProgramAccountsRequest, type GetSignatureStatusesReply, type GetSignatureStatusesReplyJson, type GetSignatureStatusesRequest, type GetSlotHeightReply, type GetSlotHeightReplyJson, type GetSlotHeightRequest, type GetTransactionReply, type GetTransactionReplyJson, type GetTransactionRequest, type WriteReportReply, type WriteReportReplyJson, type WriteReportRequest } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
2
2
  /**
3
3
  * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
4
4
  * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
5
5
  */
6
6
  export declare class SolanaMock {
7
7
  static readonly CAPABILITY_ID = "solana@1.0.0";
8
+ /** Set to define the return value for GetAccountInfoWithOpts. May return a plain object (GetAccountInfoWithOptsReplyJson) or the message type. */
9
+ getAccountInfoWithOpts?: (input: GetAccountInfoWithOptsRequest) => GetAccountInfoWithOptsReply | GetAccountInfoWithOptsReplyJson;
10
+ /** Set to define the return value for GetBalance. May return a plain object (GetBalanceReplyJson) or the message type. */
11
+ getBalance?: (input: GetBalanceRequest) => GetBalanceReply | GetBalanceReplyJson;
12
+ /** Set to define the return value for GetBlock. May return a plain object (GetBlockReplyJson) or the message type. */
13
+ getBlock?: (input: GetBlockRequest) => GetBlockReply | GetBlockReplyJson;
14
+ /** Set to define the return value for GetFeeForMessage. May return a plain object (GetFeeForMessageReplyJson) or the message type. */
15
+ getFeeForMessage?: (input: GetFeeForMessageRequest) => GetFeeForMessageReply | GetFeeForMessageReplyJson;
16
+ /** Set to define the return value for GetMultipleAccountsWithOpts. May return a plain object (GetMultipleAccountsWithOptsReplyJson) or the message type. */
17
+ getMultipleAccountsWithOpts?: (input: GetMultipleAccountsWithOptsRequest) => GetMultipleAccountsWithOptsReply | GetMultipleAccountsWithOptsReplyJson;
18
+ /** Set to define the return value for GetProgramAccounts. May return a plain object (GetProgramAccountsReplyJson) or the message type. */
19
+ getProgramAccounts?: (input: GetProgramAccountsRequest) => GetProgramAccountsReply | GetProgramAccountsReplyJson;
20
+ /** Set to define the return value for GetSignatureStatuses. May return a plain object (GetSignatureStatusesReplyJson) or the message type. */
21
+ getSignatureStatuses?: (input: GetSignatureStatusesRequest) => GetSignatureStatusesReply | GetSignatureStatusesReplyJson;
22
+ /** Set to define the return value for GetSlotHeight. May return a plain object (GetSlotHeightReplyJson) or the message type. */
23
+ getSlotHeight?: (input: GetSlotHeightRequest) => GetSlotHeightReply | GetSlotHeightReplyJson;
24
+ /** Set to define the return value for GetTransaction. May return a plain object (GetTransactionReplyJson) or the message type. */
25
+ getTransaction?: (input: GetTransactionRequest) => GetTransactionReply | GetTransactionReplyJson;
8
26
  /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
9
27
  writeReport?: (input: WriteReportRequest) => WriteReportReply | WriteReportReplyJson;
10
28
  private constructor();
@@ -1,6 +1,6 @@
1
1
  import { fromJson } from '@bufbuild/protobuf';
2
2
  import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
- import { WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
3
+ import { GetAccountInfoWithOptsReplySchema, GetAccountInfoWithOptsRequestSchema, GetBalanceReplySchema, GetBalanceRequestSchema, GetBlockReplySchema, GetBlockRequestSchema, GetFeeForMessageReplySchema, GetFeeForMessageRequestSchema, GetMultipleAccountsWithOptsReplySchema, GetMultipleAccountsWithOptsRequestSchema, GetProgramAccountsReplySchema, GetProgramAccountsRequestSchema, GetSignatureStatusesReplySchema, GetSignatureStatusesRequestSchema, GetSlotHeightReplySchema, GetSlotHeightRequestSchema, GetTransactionReplySchema, GetTransactionRequestSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
4
4
  import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
5
  /**
6
6
  * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
@@ -8,6 +8,24 @@ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, }
8
8
  */
9
9
  export class SolanaMock {
10
10
  static CAPABILITY_ID = 'solana@1.0.0';
11
+ /** Set to define the return value for GetAccountInfoWithOpts. May return a plain object (GetAccountInfoWithOptsReplyJson) or the message type. */
12
+ getAccountInfoWithOpts;
13
+ /** Set to define the return value for GetBalance. May return a plain object (GetBalanceReplyJson) or the message type. */
14
+ getBalance;
15
+ /** Set to define the return value for GetBlock. May return a plain object (GetBlockReplyJson) or the message type. */
16
+ getBlock;
17
+ /** Set to define the return value for GetFeeForMessage. May return a plain object (GetFeeForMessageReplyJson) or the message type. */
18
+ getFeeForMessage;
19
+ /** Set to define the return value for GetMultipleAccountsWithOpts. May return a plain object (GetMultipleAccountsWithOptsReplyJson) or the message type. */
20
+ getMultipleAccountsWithOpts;
21
+ /** Set to define the return value for GetProgramAccounts. May return a plain object (GetProgramAccountsReplyJson) or the message type. */
22
+ getProgramAccounts;
23
+ /** Set to define the return value for GetSignatureStatuses. May return a plain object (GetSignatureStatusesReplyJson) or the message type. */
24
+ getSignatureStatuses;
25
+ /** Set to define the return value for GetSlotHeight. May return a plain object (GetSlotHeightReplyJson) or the message type. */
26
+ getSlotHeight;
27
+ /** Set to define the return value for GetTransaction. May return a plain object (GetTransactionReplyJson) or the message type. */
28
+ getTransaction;
11
29
  /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
12
30
  writeReport;
13
31
  constructor(chainSelector) {
@@ -16,6 +34,128 @@ export class SolanaMock {
16
34
  try {
17
35
  registerTestCapability(qualifiedId, (req) => {
18
36
  switch (req.method) {
37
+ case 'GetAccountInfoWithOpts': {
38
+ const input = anyUnpack(req.payload, GetAccountInfoWithOptsRequestSchema);
39
+ const handler = self.getAccountInfoWithOpts;
40
+ if (typeof handler !== 'function')
41
+ throw new Error("GetAccountInfoWithOpts: no implementation provided; set the mock's getAccountInfoWithOpts property to define the return value.");
42
+ const raw = handler(input);
43
+ const output = raw && typeof raw.$typeName === 'string'
44
+ ? raw
45
+ : fromJson(GetAccountInfoWithOptsReplySchema, raw);
46
+ return {
47
+ response: {
48
+ case: 'payload',
49
+ value: anyPack(GetAccountInfoWithOptsReplySchema, output),
50
+ },
51
+ };
52
+ }
53
+ case 'GetBalance': {
54
+ const input = anyUnpack(req.payload, GetBalanceRequestSchema);
55
+ const handler = self.getBalance;
56
+ if (typeof handler !== 'function')
57
+ throw new Error("GetBalance: no implementation provided; set the mock's getBalance property to define the return value.");
58
+ const raw = handler(input);
59
+ const output = raw && typeof raw.$typeName === 'string'
60
+ ? raw
61
+ : fromJson(GetBalanceReplySchema, raw);
62
+ return { response: { case: 'payload', value: anyPack(GetBalanceReplySchema, output) } };
63
+ }
64
+ case 'GetBlock': {
65
+ const input = anyUnpack(req.payload, GetBlockRequestSchema);
66
+ const handler = self.getBlock;
67
+ if (typeof handler !== 'function')
68
+ throw new Error("GetBlock: no implementation provided; set the mock's getBlock property to define the return value.");
69
+ const raw = handler(input);
70
+ const output = raw && typeof raw.$typeName === 'string'
71
+ ? raw
72
+ : fromJson(GetBlockReplySchema, raw);
73
+ return { response: { case: 'payload', value: anyPack(GetBlockReplySchema, output) } };
74
+ }
75
+ case 'GetFeeForMessage': {
76
+ const input = anyUnpack(req.payload, GetFeeForMessageRequestSchema);
77
+ const handler = self.getFeeForMessage;
78
+ if (typeof handler !== 'function')
79
+ throw new Error("GetFeeForMessage: no implementation provided; set the mock's getFeeForMessage property to define the return value.");
80
+ const raw = handler(input);
81
+ const output = raw && typeof raw.$typeName === 'string'
82
+ ? raw
83
+ : fromJson(GetFeeForMessageReplySchema, raw);
84
+ return {
85
+ response: { case: 'payload', value: anyPack(GetFeeForMessageReplySchema, output) },
86
+ };
87
+ }
88
+ case 'GetMultipleAccountsWithOpts': {
89
+ const input = anyUnpack(req.payload, GetMultipleAccountsWithOptsRequestSchema);
90
+ const handler = self.getMultipleAccountsWithOpts;
91
+ if (typeof handler !== 'function')
92
+ throw new Error("GetMultipleAccountsWithOpts: no implementation provided; set the mock's getMultipleAccountsWithOpts property to define the return value.");
93
+ const raw = handler(input);
94
+ const output = raw && typeof raw.$typeName === 'string'
95
+ ? raw
96
+ : fromJson(GetMultipleAccountsWithOptsReplySchema, raw);
97
+ return {
98
+ response: {
99
+ case: 'payload',
100
+ value: anyPack(GetMultipleAccountsWithOptsReplySchema, output),
101
+ },
102
+ };
103
+ }
104
+ case 'GetProgramAccounts': {
105
+ const input = anyUnpack(req.payload, GetProgramAccountsRequestSchema);
106
+ const handler = self.getProgramAccounts;
107
+ if (typeof handler !== 'function')
108
+ throw new Error("GetProgramAccounts: no implementation provided; set the mock's getProgramAccounts property to define the return value.");
109
+ const raw = handler(input);
110
+ const output = raw && typeof raw.$typeName === 'string'
111
+ ? raw
112
+ : fromJson(GetProgramAccountsReplySchema, raw);
113
+ return {
114
+ response: { case: 'payload', value: anyPack(GetProgramAccountsReplySchema, output) },
115
+ };
116
+ }
117
+ case 'GetSignatureStatuses': {
118
+ const input = anyUnpack(req.payload, GetSignatureStatusesRequestSchema);
119
+ const handler = self.getSignatureStatuses;
120
+ if (typeof handler !== 'function')
121
+ throw new Error("GetSignatureStatuses: no implementation provided; set the mock's getSignatureStatuses property to define the return value.");
122
+ const raw = handler(input);
123
+ const output = raw && typeof raw.$typeName === 'string'
124
+ ? raw
125
+ : fromJson(GetSignatureStatusesReplySchema, raw);
126
+ return {
127
+ response: {
128
+ case: 'payload',
129
+ value: anyPack(GetSignatureStatusesReplySchema, output),
130
+ },
131
+ };
132
+ }
133
+ case 'GetSlotHeight': {
134
+ const input = anyUnpack(req.payload, GetSlotHeightRequestSchema);
135
+ const handler = self.getSlotHeight;
136
+ if (typeof handler !== 'function')
137
+ throw new Error("GetSlotHeight: no implementation provided; set the mock's getSlotHeight property to define the return value.");
138
+ const raw = handler(input);
139
+ const output = raw && typeof raw.$typeName === 'string'
140
+ ? raw
141
+ : fromJson(GetSlotHeightReplySchema, raw);
142
+ return {
143
+ response: { case: 'payload', value: anyPack(GetSlotHeightReplySchema, output) },
144
+ };
145
+ }
146
+ case 'GetTransaction': {
147
+ const input = anyUnpack(req.payload, GetTransactionRequestSchema);
148
+ const handler = self.getTransaction;
149
+ if (typeof handler !== 'function')
150
+ throw new Error("GetTransaction: no implementation provided; set the mock's getTransaction property to define the return value.");
151
+ const raw = handler(input);
152
+ const output = raw && typeof raw.$typeName === 'string'
153
+ ? raw
154
+ : fromJson(GetTransactionReplySchema, raw);
155
+ return {
156
+ response: { case: 'payload', value: anyPack(GetTransactionReplySchema, output) },
157
+ };
158
+ }
19
159
  case 'WriteReport': {
20
160
  const input = anyUnpack(req.payload, WriteReportRequestSchema);
21
161
  const handler = self.writeReport;
@@ -1,4 +1,5 @@
1
1
  /** Auto-generated barrel of capability mocks. Do not edit. */
2
+ export { AptosMock } from './capabilities/blockchain/aptos/v1alpha/aptos_mock_gen';
2
3
  export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
3
4
  export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
4
5
  export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
@@ -1,4 +1,5 @@
1
1
  /** Auto-generated barrel of capability mocks. Do not edit. */
2
+ export { AptosMock } from './capabilities/blockchain/aptos/v1alpha/aptos_mock_gen';
2
3
  export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
3
4
  export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
4
5
  export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
@@ -6,4 +6,3 @@ export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabil
6
6
  export { TestWriter } from '../testutils/test-writer';
7
7
  export { type AddContractMockOptions, addContractMock, type ContractMock, type WriteReportMockInput, } from './evm-contract-mock';
8
8
  export * from './generated';
9
- export { type AddSolanaContractMockOptions, addSolanaContractMock, type SolanaContractMock, type SolanaWriteReportMockInput, } from './solana-contract-mock';
@@ -6,4 +6,3 @@ export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRunti
6
6
  export { TestWriter } from '../testutils/test-writer';
7
7
  export { addContractMock, } from './evm-contract-mock';
8
8
  export * from './generated';
9
- export { addSolanaContractMock, } from './solana-contract-mock';
@@ -2,5 +2,5 @@
2
2
  * Test-only utilities for the CRE SDK runtime. Not part of the public API.
3
3
  * Use for unit testing runtime logic without the WASM execution environment.
4
4
  */
5
- export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState, test, } from './test-runtime';
5
+ export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState, TestTeeRuntime, test, } from './test-runtime';
6
6
  export { TestWriter } from './test-writer';
@@ -2,5 +2,5 @@
2
2
  * Test-only utilities for the CRE SDK runtime. Not part of the public API.
3
3
  * Use for unit testing runtime logic without the WASM execution environment.
4
4
  */
5
- export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime, test, } from './test-runtime';
5
+ export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime, TestTeeRuntime, test, } from './test-runtime';
6
6
  export { TestWriter } from './test-writer';
@@ -3,8 +3,9 @@
3
3
  * Registry is scoped per test via AsyncLocalStorage; use testWithRuntime to run tests with a registry.
4
4
  */
5
5
  import type { Any } from '@bufbuild/protobuf/wkt';
6
+ import type { WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
6
7
  import type { RuntimeHelpers } from '../impl/runtime-impl';
7
- import { RuntimeImpl } from '../impl/runtime-impl';
8
+ import { RuntimeImpl, TeeRuntimeImpl } from '../impl/runtime-impl';
8
9
  import { TestWriter } from './test-writer';
9
10
  /** Error message when response exceeds max size. Used by the harness when its await implements the size check. */
10
11
  export declare const RESPONSE_BUFFER_TOO_SMALL = "response buffer too small";
@@ -70,15 +71,27 @@ export declare function test(title: string, fn: () => void | Promise<void>): voi
70
71
  /**
71
72
  * Creates a test runtime. This must be called from within a test in this package.
72
73
  */
73
- export declare function newTestRuntime(secrets?: Secrets | null, options?: NewTestRuntimeOptions): TestRuntime;
74
+ export declare function newTestRuntime<T = unknown>(secrets?: Secrets | null, options?: NewTestRuntimeOptions, config?: T | undefined): TestRuntime<T>;
74
75
  /**
75
76
  * TestRuntime is a Runtime implementation for unit tests. Extends RuntimeImpl; construct via newTestRuntime.
76
77
  * Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
77
78
  */
78
- export declare class TestRuntime extends RuntimeImpl<unknown> {
79
+ export declare class TestRuntime<T> extends RuntimeImpl<T> {
79
80
  private readonly testWriter;
80
81
  private readonly state;
81
- constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState);
82
+ constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState, config?: T | undefined);
82
83
  getLogs(): string[];
83
84
  setTimeProvider(timeProvider: () => number): void;
84
85
  }
86
+ /**
87
+ * TestTeeRuntime is a TeeRuntime implementation for unit tests. Extends TeeRuntimeImpl; construct via newTestTEERuntime.
88
+ * Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
89
+ */
90
+ export declare class TestTeeRuntime<T> extends TeeRuntimeImpl<T> {
91
+ private readonly testWriter;
92
+ private readonly state;
93
+ constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState, config: T);
94
+ getLogs(): string[];
95
+ getMetrics(): WorkflowUserMetric[];
96
+ setTimeProvider(timeProvider: () => number): void;
97
+ }
@@ -8,7 +8,7 @@ import { create, toBinary } from '@bufbuild/protobuf';
8
8
  import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
9
9
  import { AttributedSignatureSchema, AwaitCapabilitiesResponseSchema, AwaitSecretsResponseSchema, CapabilityResponseSchema, ReportRequestSchema, ReportResponseSchema, SecretErrorSchema, SecretResponseSchema, SecretResponsesSchema, SecretSchema, SimpleConsensusInputsSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
10
10
  import { ValueSchema } from '../../generated/values/v1/values_pb';
11
- import { RuntimeImpl } from '../impl/runtime-impl';
11
+ import { RuntimeImpl, TeeRuntimeImpl } from '../impl/runtime-impl';
12
12
  import { TestWriter } from './test-writer';
13
13
  /** Error message when response exceeds max size. Used by the harness when its await implements the size check. */
14
14
  export const RESPONSE_BUFFER_TOO_SMALL = 'response buffer too small';
@@ -239,6 +239,10 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
239
239
  log(message) {
240
240
  testWriter.log(message);
241
241
  },
242
+ emitMetric(payload) {
243
+ testWriter.emitMetric(payload);
244
+ return true;
245
+ },
242
246
  };
243
247
  }
244
248
  /**
@@ -258,7 +262,7 @@ export function test(title, fn) {
258
262
  /**
259
263
  * Creates a test runtime. This must be called from within a test in this package.
260
264
  */
261
- export function newTestRuntime(secrets, options = {}) {
265
+ export function newTestRuntime(secrets, options = {}, config = undefined) {
262
266
  const secretsMap = secrets ?? new Map();
263
267
  const testWriter = new TestWriter();
264
268
  const registry = registryStorage.getStore() ?? new Registry();
@@ -297,7 +301,7 @@ export function newTestRuntime(secrets, options = {}) {
297
301
  }
298
302
  const maxResponseSize = BigInt(configuredMaxResponseSize);
299
303
  const helpers = createTestRuntimeHelpers(registry, secretsMap, testWriter, state, maxResponseSize);
300
- return new TestRuntime(helpers, maxResponseSize, testWriter, state);
304
+ return new TestRuntime(helpers, maxResponseSize, testWriter, state, config);
301
305
  }
302
306
  /**
303
307
  * TestRuntime is a Runtime implementation for unit tests. Extends RuntimeImpl; construct via newTestRuntime.
@@ -306,14 +310,36 @@ export function newTestRuntime(secrets, options = {}) {
306
310
  export class TestRuntime extends RuntimeImpl {
307
311
  testWriter;
308
312
  state;
309
- constructor(helpers, maxResponseSize, testWriter, state) {
310
- super({}, 0, helpers, maxResponseSize);
313
+ constructor(helpers, maxResponseSize, testWriter, state, config = undefined) {
314
+ super(config ?? {}, 0, helpers, maxResponseSize);
315
+ this.testWriter = testWriter;
316
+ this.state = state;
317
+ }
318
+ getLogs() {
319
+ return this.testWriter.getLogs();
320
+ }
321
+ setTimeProvider(timeProvider) {
322
+ this.state.timeProvider = timeProvider;
323
+ }
324
+ }
325
+ /**
326
+ * TestTeeRuntime is a TeeRuntime implementation for unit tests. Extends TeeRuntimeImpl; construct via newTestTEERuntime.
327
+ * Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
328
+ */
329
+ export class TestTeeRuntime extends TeeRuntimeImpl {
330
+ testWriter;
331
+ state;
332
+ constructor(helpers, maxResponseSize, testWriter, state, config) {
333
+ super(config, 0, helpers, maxResponseSize);
311
334
  this.testWriter = testWriter;
312
335
  this.state = state;
313
336
  }
314
337
  getLogs() {
315
338
  return this.testWriter.getLogs();
316
339
  }
340
+ getMetrics() {
341
+ return this.testWriter.getMetrics();
342
+ }
317
343
  setTimeProvider(timeProvider) {
318
344
  this.state.timeProvider = timeProvider;
319
345
  }
@@ -1,13 +1,19 @@
1
+ import { type WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
1
2
  /**
2
3
  * In-memory log sink for tests. Captures messages so tests can assert on log output.
3
4
  * Equivalent to Go's cre/testutils/test_writer.go.
4
5
  */
5
6
  export declare class TestWriter {
6
7
  private logs;
8
+ private metrics;
7
9
  /** Appends a message to the captured log buffer. */
8
10
  log(message: string): void;
9
11
  /** Returns a copy of all captured log messages in order. */
10
12
  getLogs(): string[];
11
- /** Clears the captured log buffer. */
13
+ /** Captures a serialized WorkflowUserMetric payload. */
14
+ emitMetric(payload: Uint8Array): void;
15
+ /** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
16
+ getMetrics(): WorkflowUserMetric[];
17
+ /** Clears captured logs and metrics. */
12
18
  clear(): void;
13
19
  }
@@ -1,9 +1,12 @@
1
+ import { fromBinary } from '@bufbuild/protobuf';
2
+ import { WorkflowUserMetricSchema, } from '../../generated/workflows/v2/workflow_user_metric_pb';
1
3
  /**
2
4
  * In-memory log sink for tests. Captures messages so tests can assert on log output.
3
5
  * Equivalent to Go's cre/testutils/test_writer.go.
4
6
  */
5
7
  export class TestWriter {
6
8
  logs = [];
9
+ metrics = [];
7
10
  /** Appends a message to the captured log buffer. */
8
11
  log(message) {
9
12
  this.logs.push(message);
@@ -12,8 +15,17 @@ export class TestWriter {
12
15
  getLogs() {
13
16
  return [...this.logs];
14
17
  }
15
- /** Clears the captured log buffer. */
18
+ /** Captures a serialized WorkflowUserMetric payload. */
19
+ emitMetric(payload) {
20
+ this.metrics.push(payload);
21
+ }
22
+ /** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
23
+ getMetrics() {
24
+ return this.metrics.map((bytes) => fromBinary(WorkflowUserMetricSchema, bytes));
25
+ }
26
+ /** Clears captured logs and metrics. */
16
27
  clear() {
17
28
  this.logs = [];
29
+ this.metrics = [];
18
30
  }
19
31
  }
@@ -45,6 +45,14 @@ declare global {
45
45
  */
46
46
  function log(message: string): void
47
47
 
48
+ /**
49
+ * Emits a user metric to the host. The payload is a protobuf-encoded
50
+ * `workflows.v2.WorkflowUserMetric` message.
51
+ * @param payload - protobuf-encoded WorkflowUserMetric bytes
52
+ * @returns 0 on success, negative on error (rate-limited, oversized, invalid name, etc.)
53
+ */
54
+ function emitMetric(payload: Uint8Array): number
55
+
48
56
  /**
49
57
  * Sends a response back to the host
50
58
  * @param response - bytes response
@@ -1,8 +1,7 @@
1
- import type { CallMsgJson, FilterLogTriggerRequestJson } from '../../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
2
- import type { ReportRequestJson } from '../../../../../generated/sdk/v1alpha/sdk_pb';
3
- import { type BigInt as GeneratedBigInt } from '../../../../../generated/values/v1/values_pb';
1
+ import type { CallMsgJson, FilterLogTriggerRequestJson } from '../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
2
+ import type { ReportRequestJson } from '../../../../generated/sdk/v1alpha/sdk_pb';
3
+ import { type BigInt as GeneratedBigInt } from '../../../../generated/values/v1/values_pb';
4
4
  import type { Address, Hex } from 'viem';
5
- import { type ReportEncoder } from '../report-helpers';
6
5
  /**
7
6
  * Protobuf BigInt structure returned by SDK methods (e.g., headerByNumber).
8
7
  * Uses Pick to extract just the data fields from the generated type.
@@ -21,7 +20,7 @@ export type ProtoBigInt = Pick<GeneratedBigInt, 'absVal' | 'sign'>;
21
20
  * @param n - The native bigint, number, or string value.
22
21
  * @returns The protobuf BigInt JSON representation.
23
22
  */
24
- export declare const bigintToProtoBigInt: (n: number | bigint | string) => import("../../../../../generated/values/v1/values_pb").BigIntJson;
23
+ export declare const bigintToProtoBigInt: (n: number | bigint | string) => import("../../../../generated/values/v1/values_pb").BigIntJson;
25
24
  /**
26
25
  * Converts a protobuf BigInt to a native JS bigint.
27
26
  * Use this when extracting bigint values from SDK responses.
@@ -42,7 +41,7 @@ export declare const protoBigIntToBigint: (pb: ProtoBigInt) => bigint;
42
41
  * @param n - The block number.
43
42
  * @returns The protobuf BigInt JSON representation.
44
43
  */
45
- export declare const blockNumber: (n: number | bigint | string) => import("../../../../../generated/values/v1/values_pb").BigIntJson;
44
+ export declare const blockNumber: (n: number | bigint | string) => import("../../../../generated/values/v1/values_pb").BigIntJson;
46
45
  /**
47
46
  * EVM Capability Helper.
48
47
  *
@@ -107,7 +106,7 @@ export declare const EVM_DEFAULT_REPORT_ENCODER: {
107
106
  * @param reportEncoder - The report encoder to be used. Defaults to EVM_DEFAULT_REPORT_ENCODER.
108
107
  * @returns The prepared report request.
109
108
  */
110
- export declare const prepareReportRequest: (hexEncodedPayload: Hex, reportEncoder?: ReportEncoder) => ReportRequestJson;
109
+ export declare const prepareReportRequest: (hexEncodedPayload: Hex, reportEncoder?: Omit<ReportRequestJson, "encodedPayload">) => ReportRequestJson;
111
110
  export interface LogTriggerConfigOptions {
112
111
  /** EVM addresses to monitor — hex strings with 0x prefix (20 bytes each) */
113
112
  addresses: Hex[];
@@ -1,9 +1,8 @@
1
1
  import { create, toJson } from '@bufbuild/protobuf';
2
- import { BigIntSchema } from '../../../../../generated/values/v1/values_pb';
3
- import { EVMClient } from '../../../../cre';
4
- import { bigintToBytes, bytesToBigint, hexToBase64, hexToBytes } from '../../../hex-utils';
5
- import { assertSafeIntegerNumber } from '../../../safe-integer';
6
- import { prepareReportRequestFromBytes } from '../report-helpers';
2
+ import { BigIntSchema } from '../../../../generated/values/v1/values_pb';
3
+ import { EVMClient } from '../../../cre';
4
+ import { bigintToBytes, bytesToBigint, hexToBase64, hexToBytes } from '../../hex-utils';
5
+ import { assertSafeIntegerNumber } from '../../safe-integer';
7
6
  /**
8
7
  * Converts a native JS bigint to a protobuf BigInt JSON representation.
9
8
  * Use this when passing bigint values to SDK methods.
@@ -127,7 +126,10 @@ export const EVM_DEFAULT_REPORT_ENCODER = {
127
126
  * @param reportEncoder - The report encoder to be used. Defaults to EVM_DEFAULT_REPORT_ENCODER.
128
127
  * @returns The prepared report request.
129
128
  */
130
- export const prepareReportRequest = (hexEncodedPayload, reportEncoder = EVM_DEFAULT_REPORT_ENCODER) => prepareReportRequestFromBytes(hexToBytes(hexEncodedPayload), reportEncoder);
129
+ export const prepareReportRequest = (hexEncodedPayload, reportEncoder = EVM_DEFAULT_REPORT_ENCODER) => ({
130
+ encodedPayload: hexToBase64(hexEncodedPayload),
131
+ ...reportEncoder,
132
+ });
131
133
  /**
132
134
  * Validates a hex string and checks that the decoded bytes have the expected length.
133
135
  */
@@ -13,12 +13,6 @@ export declare const hexToBytes: (hexStr: string) => Uint8Array;
13
13
  * Convert Uint8Array to hex string with 0x prefix
14
14
  */
15
15
  export declare const bytesToHex: (bytes: Uint8Array) => Hex;
16
- /**
17
- * Encode raw bytes as base64 string
18
- * @param bytes
19
- * @returns
20
- */
21
- export declare const bytesToBase64: (bytes: Uint8Array) => string;
22
16
  /**
23
17
  * Encode hex as base64 string
24
18
  * @param hex
@@ -28,14 +28,6 @@ export const bytesToHex = (bytes) => {
28
28
  .map((b) => b.toString(16).padStart(2, '0'))
29
29
  .join('')}`;
30
30
  };
31
- /**
32
- * Encode raw bytes as base64 string
33
- * @param bytes
34
- * @returns
35
- */
36
- export const bytesToBase64 = (bytes) => {
37
- return Buffer.from(bytes).toString('base64');
38
- };
39
31
  /**
40
32
  * Encode hex as base64 string
41
33
  * @param hex