@agoric/orchestration 0.1.1-dev-ad4cd18.0.ad4cd18 → 0.1.1-dev-a6c0604.0.a6c0604
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.
- package/package.json +16 -16
- package/tools/contract-tests.d.ts.map +1 -1
- package/tools/contract-tests.ts +1 -1
- package/tools/ibc-mock-fixtures.d.ts +49 -0
- package/tools/ibc-mock-fixtures.d.ts.map +1 -0
- package/tools/ibc-mock-fixtures.ts +161 -0
- package/tools/network-fakes.d.ts +142 -0
- package/tools/network-fakes.d.ts.map +1 -0
- package/tools/network-fakes.ts +389 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/orchestration",
|
|
3
|
-
"version": "0.1.1-dev-
|
|
3
|
+
"version": "0.1.1-dev-a6c0604.0.a6c0604",
|
|
4
4
|
"description": "Chain abstraction for Agoric's orchestration clients",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@agoric/async-flow": "0.1.1-dev-
|
|
39
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
40
|
-
"@agoric/ertp": "0.16.3-dev-
|
|
41
|
-
"@agoric/internal": "0.3.3-dev-
|
|
42
|
-
"@agoric/network": "0.1.1-dev-
|
|
43
|
-
"@agoric/notifier": "0.6.3-dev-
|
|
44
|
-
"@agoric/store": "0.9.3-dev-
|
|
45
|
-
"@agoric/time": "0.3.3-dev-
|
|
46
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
47
|
-
"@agoric/vats": "0.15.2-dev-
|
|
48
|
-
"@agoric/vow": "0.1.1-dev-
|
|
49
|
-
"@agoric/zoe": "0.26.3-dev-
|
|
50
|
-
"@agoric/zone": "0.2.3-dev-
|
|
38
|
+
"@agoric/async-flow": "0.1.1-dev-a6c0604.0.a6c0604",
|
|
39
|
+
"@agoric/cosmic-proto": "0.4.1-dev-a6c0604.0.a6c0604",
|
|
40
|
+
"@agoric/ertp": "0.16.3-dev-a6c0604.0.a6c0604",
|
|
41
|
+
"@agoric/internal": "0.3.3-dev-a6c0604.0.a6c0604",
|
|
42
|
+
"@agoric/network": "0.1.1-dev-a6c0604.0.a6c0604",
|
|
43
|
+
"@agoric/notifier": "0.6.3-dev-a6c0604.0.a6c0604",
|
|
44
|
+
"@agoric/store": "0.9.3-dev-a6c0604.0.a6c0604",
|
|
45
|
+
"@agoric/time": "0.3.3-dev-a6c0604.0.a6c0604",
|
|
46
|
+
"@agoric/vat-data": "0.5.3-dev-a6c0604.0.a6c0604",
|
|
47
|
+
"@agoric/vats": "0.15.2-dev-a6c0604.0.a6c0604",
|
|
48
|
+
"@agoric/vow": "0.1.1-dev-a6c0604.0.a6c0604",
|
|
49
|
+
"@agoric/zoe": "0.26.3-dev-a6c0604.0.a6c0604",
|
|
50
|
+
"@agoric/zone": "0.2.3-dev-a6c0604.0.a6c0604",
|
|
51
51
|
"@cosmjs/encoding": "^0.36.0",
|
|
52
52
|
"@endo/base64": "^1.0.12",
|
|
53
53
|
"@endo/errors": "^1.2.13",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"bs58": "^6.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
64
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-a6c0604.0.a6c0604",
|
|
65
65
|
"@chain-registry/client": "^1.53.194",
|
|
66
66
|
"@cosmjs/amino": "^0.36.0",
|
|
67
67
|
"@cosmjs/proto-signing": "^0.36.0",
|
|
@@ -105,5 +105,5 @@
|
|
|
105
105
|
"typeCoverage": {
|
|
106
106
|
"atLeast": 97.65
|
|
107
107
|
},
|
|
108
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "a6c06040100171553fdf07d11e906d073c019dee"
|
|
109
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-tests.d.ts","sourceRoot":"","sources":["contract-tests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yDAAyD,CAAC;AAE3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAS/E,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAmBtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAQpE,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,GAAG,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAU,kBAG1C;IACD,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACpC;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"contract-tests.d.ts","sourceRoot":"","sources":["contract-tests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yDAAyD,CAAC;AAE3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAS/E,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAmBtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAQpE,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,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JH,kGAAkG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAnJnE,MAAM;qBAT9B,WAAW;sBACV,MAAM;;;wCA2DT,iBAAiB,CAAC,OAAO,CAAC,SAC1B,MAAM,GAAG;YAAE,OAAO,EAAE,WAAW,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,yBACnC,MAAM;;;;2BAcS,YAAY;;;;;;;;;EAmGrD,CAAC"}
|
package/tools/contract-tests.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
makeAsyncQueue,
|
|
7
7
|
makeFakeStorageKit,
|
|
8
8
|
} from '@agoric/internal/src/storage-test-utils.js';
|
|
9
|
-
import { setupFakeNetwork } from '@agoric/orchestration/
|
|
9
|
+
import { setupFakeNetwork } from '@agoric/orchestration/tools/network-fakes.js';
|
|
10
10
|
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
|
|
11
11
|
import { buildVTransferEvent } from '@agoric/orchestration/tools/ibc-mocks.js';
|
|
12
12
|
import {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: provide mappings to cosmos error codes (and module specific error codes)
|
|
3
|
+
* see https://github.com/Agoric/agoric-sdk/issues/9629 for more details about
|
|
4
|
+
* error messages over ibc
|
|
5
|
+
*/
|
|
6
|
+
export declare const errorAcknowledgments: {
|
|
7
|
+
error5: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const UNBOND_PERIOD_SECONDS = 5n;
|
|
10
|
+
export declare const protoMsgMocks: {
|
|
11
|
+
delegate: {
|
|
12
|
+
msg: string;
|
|
13
|
+
ack: string;
|
|
14
|
+
};
|
|
15
|
+
undelegate: {
|
|
16
|
+
msg: string;
|
|
17
|
+
ack: string;
|
|
18
|
+
};
|
|
19
|
+
redelegate: {
|
|
20
|
+
msg: string;
|
|
21
|
+
ack: string;
|
|
22
|
+
};
|
|
23
|
+
withdrawReward: {
|
|
24
|
+
msg: string;
|
|
25
|
+
ack: string;
|
|
26
|
+
};
|
|
27
|
+
queryBalance: {
|
|
28
|
+
msg: string;
|
|
29
|
+
ack: string;
|
|
30
|
+
};
|
|
31
|
+
bankSend: {
|
|
32
|
+
msg: string;
|
|
33
|
+
ack: string;
|
|
34
|
+
};
|
|
35
|
+
bankSendMulti: {
|
|
36
|
+
msg: string;
|
|
37
|
+
ack: string;
|
|
38
|
+
};
|
|
39
|
+
depositForBurn: {
|
|
40
|
+
msg: string;
|
|
41
|
+
ack: string;
|
|
42
|
+
};
|
|
43
|
+
depositForBurnForBase: {
|
|
44
|
+
msg: string;
|
|
45
|
+
ack: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export declare const defaultMockAckMap: Record<string, string>;
|
|
49
|
+
//# sourceMappingURL=ibc-mock-fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ibc-mock-fixtures.d.ts","sourceRoot":"","sources":["ibc-mock-fixtures.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;CAIhC,CAAC;AAiCF,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAOxC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwEzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CACpB,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/** @file Canned IBC message and acknowledgement fixtures for tests and fakes */
|
|
2
|
+
import {
|
|
3
|
+
QueryBalanceRequest,
|
|
4
|
+
QueryBalanceResponse,
|
|
5
|
+
} from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js';
|
|
6
|
+
import {
|
|
7
|
+
MsgSend,
|
|
8
|
+
MsgSendResponse,
|
|
9
|
+
} from '@agoric/cosmic-proto/cosmos/bank/v1beta1/tx.js';
|
|
10
|
+
import {
|
|
11
|
+
MsgDepositForBurn,
|
|
12
|
+
MsgDepositForBurnResponse,
|
|
13
|
+
} from '@agoric/cosmic-proto/circle/cctp/v1/tx.js';
|
|
14
|
+
import {
|
|
15
|
+
MsgWithdrawDelegatorReward,
|
|
16
|
+
MsgWithdrawDelegatorRewardResponse,
|
|
17
|
+
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/tx.js';
|
|
18
|
+
import type { Timestamp } from '@agoric/cosmic-proto/google/protobuf/timestamp.js';
|
|
19
|
+
import {
|
|
20
|
+
MsgBeginRedelegate,
|
|
21
|
+
MsgBeginRedelegateResponse,
|
|
22
|
+
MsgDelegate,
|
|
23
|
+
MsgDelegateResponse,
|
|
24
|
+
MsgUndelegate,
|
|
25
|
+
MsgUndelegateResponse,
|
|
26
|
+
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
|
|
27
|
+
import {
|
|
28
|
+
buildMsgErrorString,
|
|
29
|
+
buildMsgResponseString,
|
|
30
|
+
buildQueryPacketString,
|
|
31
|
+
buildQueryResponseString,
|
|
32
|
+
buildTxPacketString,
|
|
33
|
+
createMockAckMap,
|
|
34
|
+
} from './ibc-mocks.js';
|
|
35
|
+
import { leftPadEthAddressTo32Bytes } from '../src/utils/address.js';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* TODO: provide mappings to cosmos error codes (and module specific error codes)
|
|
39
|
+
* see https://github.com/Agoric/agoric-sdk/issues/9629 for more details about
|
|
40
|
+
* error messages over ibc
|
|
41
|
+
*/
|
|
42
|
+
export const errorAcknowledgments = {
|
|
43
|
+
error5: buildMsgErrorString(
|
|
44
|
+
'ABCI code: 5: error handling packet: see events for details',
|
|
45
|
+
),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const delegation = {
|
|
49
|
+
amount: {
|
|
50
|
+
denom: 'uatom',
|
|
51
|
+
amount: '10',
|
|
52
|
+
},
|
|
53
|
+
delegatorAddress: 'cosmos1test',
|
|
54
|
+
validatorAddress: 'cosmosvaloper1test',
|
|
55
|
+
};
|
|
56
|
+
const redelegation = {
|
|
57
|
+
delegatorAddress: 'cosmos1test',
|
|
58
|
+
validatorSrcAddress: 'cosmosvaloper1test',
|
|
59
|
+
validatorDstAddress: 'cosmosvaloper2test',
|
|
60
|
+
amount: {
|
|
61
|
+
denom: 'uatom',
|
|
62
|
+
amount: '10',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const bankSend = {
|
|
66
|
+
fromAddress: 'cosmos1test',
|
|
67
|
+
toAddress: 'cosmos1testrecipient',
|
|
68
|
+
amount: [{ denom: 'uatom', amount: '10' }],
|
|
69
|
+
};
|
|
70
|
+
const bankSendMulti = {
|
|
71
|
+
fromAddress: 'cosmos1test',
|
|
72
|
+
toAddress: 'cosmos1testrecipient',
|
|
73
|
+
amount: [
|
|
74
|
+
{ denom: 'uatom', amount: '10' },
|
|
75
|
+
{ denom: 'ibc/1234', amount: '10' },
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const UNBOND_PERIOD_SECONDS = 5n;
|
|
80
|
+
|
|
81
|
+
const getUnbondingTime = (): Timestamp => ({
|
|
82
|
+
seconds: UNBOND_PERIOD_SECONDS,
|
|
83
|
+
nanos: 0,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const protoMsgMocks = {
|
|
87
|
+
delegate: {
|
|
88
|
+
msg: buildTxPacketString([MsgDelegate.toProtoMsg(delegation)]),
|
|
89
|
+
ack: buildMsgResponseString(MsgDelegateResponse, {}),
|
|
90
|
+
},
|
|
91
|
+
undelegate: {
|
|
92
|
+
msg: buildTxPacketString([MsgUndelegate.toProtoMsg(delegation)]),
|
|
93
|
+
ack: buildMsgResponseString(MsgUndelegateResponse, {
|
|
94
|
+
completionTime: getUnbondingTime(),
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
redelegate: {
|
|
98
|
+
msg: buildTxPacketString([MsgBeginRedelegate.toProtoMsg(redelegation)]),
|
|
99
|
+
ack: buildMsgResponseString(MsgBeginRedelegateResponse, {
|
|
100
|
+
completionTime: getUnbondingTime(),
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
withdrawReward: {
|
|
104
|
+
msg: buildTxPacketString([
|
|
105
|
+
MsgWithdrawDelegatorReward.toProtoMsg(delegation),
|
|
106
|
+
]),
|
|
107
|
+
ack: buildMsgResponseString(MsgWithdrawDelegatorRewardResponse, {
|
|
108
|
+
amount: [{ amount: '1', denom: 'uatom' }],
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
queryBalance: {
|
|
112
|
+
msg: buildQueryPacketString([
|
|
113
|
+
QueryBalanceRequest.toProtoMsg({
|
|
114
|
+
address: 'cosmos1test',
|
|
115
|
+
denom: 'uatom',
|
|
116
|
+
}),
|
|
117
|
+
]),
|
|
118
|
+
ack: buildQueryResponseString(QueryBalanceResponse, {
|
|
119
|
+
balance: { amount: '0', denom: 'uatom' },
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
122
|
+
bankSend: {
|
|
123
|
+
msg: buildTxPacketString([MsgSend.toProtoMsg(bankSend)]),
|
|
124
|
+
ack: buildMsgResponseString(MsgSendResponse, {}),
|
|
125
|
+
},
|
|
126
|
+
bankSendMulti: {
|
|
127
|
+
msg: buildTxPacketString([MsgSend.toProtoMsg(bankSendMulti)]),
|
|
128
|
+
ack: buildMsgResponseString(MsgSendResponse, {}),
|
|
129
|
+
},
|
|
130
|
+
depositForBurn: {
|
|
131
|
+
msg: buildTxPacketString([
|
|
132
|
+
MsgDepositForBurn.toProtoMsg({
|
|
133
|
+
amount: '4250000',
|
|
134
|
+
burnToken: 'uusdc',
|
|
135
|
+
from: 'cosmos1test',
|
|
136
|
+
destinationDomain: 6,
|
|
137
|
+
mintRecipient: leftPadEthAddressTo32Bytes(
|
|
138
|
+
'0x20E68F6c276AC6E297aC46c84Ab260928276691D',
|
|
139
|
+
),
|
|
140
|
+
}),
|
|
141
|
+
]),
|
|
142
|
+
ack: buildMsgResponseString(MsgDepositForBurnResponse, {}),
|
|
143
|
+
},
|
|
144
|
+
depositForBurnForBase: {
|
|
145
|
+
msg: buildTxPacketString([
|
|
146
|
+
MsgDepositForBurn.toProtoMsg({
|
|
147
|
+
amount: '10',
|
|
148
|
+
burnToken: 'uusdc',
|
|
149
|
+
from: 'cosmos1test',
|
|
150
|
+
destinationDomain: 0,
|
|
151
|
+
mintRecipient: leftPadEthAddressTo32Bytes(
|
|
152
|
+
'0xe0d43135EBd2593907F8f56c25ADC1Bf94FCf993',
|
|
153
|
+
),
|
|
154
|
+
}),
|
|
155
|
+
]),
|
|
156
|
+
ack: buildMsgResponseString(MsgDepositForBurnResponse, {}),
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const defaultMockAckMap: Record<string, string> =
|
|
161
|
+
createMockAckMap(protoMsgMocks);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { VowTools } from '@agoric/vow';
|
|
2
|
+
import type { Zone } from '@agoric/zone';
|
|
3
|
+
import type { IBCChannelID, IBCMethod, IBCEvent, ScopedBridgeManagerMethods } from '@agoric/vats';
|
|
4
|
+
import type { Guarded } from '@endo/exo';
|
|
5
|
+
type ImplementedIBCEvents = 'channelOpenAck' | 'acknowledgementPacket';
|
|
6
|
+
export declare const ibcBridgeMocks: {
|
|
7
|
+
[T in ImplementedIBCEvents]: T extends 'channelOpenAck' ? (obj: IBCMethod<'startChannelOpenInit'>, opts: {
|
|
8
|
+
channelID: IBCChannelID;
|
|
9
|
+
counterpartyChannelID: IBCChannelID;
|
|
10
|
+
mockChainAddress: string;
|
|
11
|
+
}) => IBCEvent<'channelOpenAck'> : T extends 'acknowledgementPacket' ? (obj: IBCMethod<'sendPacket'>, opts: {
|
|
12
|
+
sequence: bigint;
|
|
13
|
+
acknowledgement: string;
|
|
14
|
+
}) => IBCEvent<'acknowledgementPacket'> : never;
|
|
15
|
+
};
|
|
16
|
+
type BridgeEvents = Array<IBCEvent<'channelOpenAck'> | IBCEvent<'acknowledgementPacket'> | IBCEvent<'channelCloseConfirm'> | IBCEvent<'sendPacket'>>;
|
|
17
|
+
type BridgeDowncalls = Array<IBCMethod<'startChannelOpenInit'> | IBCMethod<'startChannelCloseInit'> | IBCMethod<'bindPort'> | IBCMethod<'sendPacket'>>;
|
|
18
|
+
/**
|
|
19
|
+
* Make a fake IBC Bridge, extended from the dibc ScopedBridgeManager.
|
|
20
|
+
*
|
|
21
|
+
* Has extra `setMockAck` and `setAddressPrefix` methods.
|
|
22
|
+
*
|
|
23
|
+
* @param zone
|
|
24
|
+
*/
|
|
25
|
+
export declare const makeFakeIBCBridge: (zone: Zone) => Guarded<ScopedBridgeManagerMethods<"dibc"> & {
|
|
26
|
+
addMockAck: (msgData: string, ackData: string) => void;
|
|
27
|
+
setMockAck: (mockAckMap: Record<string, string>) => void;
|
|
28
|
+
setAddressPrefix: (addressPrefix: string) => void;
|
|
29
|
+
inspectDibcBridge: () => {
|
|
30
|
+
bridgeEvents: BridgeEvents;
|
|
31
|
+
bridgeDowncalls: BridgeDowncalls;
|
|
32
|
+
};
|
|
33
|
+
}>;
|
|
34
|
+
export declare const setupFakeNetwork: (zone: Zone, { vowTools }: {
|
|
35
|
+
vowTools: VowTools;
|
|
36
|
+
}) => {
|
|
37
|
+
portAllocator: Guarded<{
|
|
38
|
+
allocateCustomIBCPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
39
|
+
allocateICAControllerPort(): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
40
|
+
allocateICQControllerPort(): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
41
|
+
allocateCustomLocalPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
42
|
+
}>;
|
|
43
|
+
protocol: Guarded<{
|
|
44
|
+
registerProtocolHandler(paths: string[], protocolHandler: import("@agoric/vow").Remote<import("@agoric/network").ProtocolHandler>): void;
|
|
45
|
+
unregisterProtocolHandler(prefix: string, protocolHandler: import("@agoric/vow").Remote<import("@agoric/network").ProtocolHandler>): void;
|
|
46
|
+
bindPort(localAddr: import("@agoric/network").Endpoint): Promise<import("@agoric/network").Port | import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
47
|
+
}>;
|
|
48
|
+
ibcBridge: Guarded<ScopedBridgeManagerMethods<"dibc"> & {
|
|
49
|
+
addMockAck: (msgData: string, ackData: string) => void;
|
|
50
|
+
setMockAck: (mockAckMap: Record<string, string>) => void;
|
|
51
|
+
setAddressPrefix: (addressPrefix: string) => void;
|
|
52
|
+
inspectDibcBridge: () => {
|
|
53
|
+
bridgeEvents: BridgeEvents;
|
|
54
|
+
bridgeDowncalls: BridgeDowncalls;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
networkVat: {
|
|
58
|
+
registerProtocolHandler: (prefixes: any, handler: any) => void;
|
|
59
|
+
makeLoopbackProtocolHandler: (instancePrefix?: string) => Guarded<{
|
|
60
|
+
onCreate(_impl: any, _protocolHandler: any): Promise<void>;
|
|
61
|
+
generatePortID(_localAddr: any, _protocolHandler: any): Promise<string>;
|
|
62
|
+
onBind(_port: any, _localAddr: any, _protocolHandler: any): Promise<void>;
|
|
63
|
+
onConnect(_port: any, localAddr: import("@agoric/network").Endpoint, remoteAddr: import("@agoric/network").Endpoint): import("@agoric/vow").PromiseVow<import("@agoric/network").AttemptDescription>;
|
|
64
|
+
onInstantiate(_port: any, _localAddr: any, _remote: any, _protocol: any): Promise<string>;
|
|
65
|
+
onListen(port: any, localAddr: any, listenHandler: any, _protocolHandler: any): Promise<void>;
|
|
66
|
+
onListenRemove(port: import("@agoric/vow").Remote<import("@agoric/network").Port>, localAddr: import("@agoric/network").Endpoint, listenHandler: import("@agoric/vow").Remote<import("@agoric/network").ListenHandler>, _protocolHandler: any): Promise<void>;
|
|
67
|
+
onRevoke(_port: any, _localAddr: any, _protocolHandler: any): Promise<void>;
|
|
68
|
+
}>;
|
|
69
|
+
makeEchoConnectionKit: () => import("@endo/exo").GuardedKit<{
|
|
70
|
+
handler: {
|
|
71
|
+
onReceive(_connection: import("@agoric/network").Connection, bytes: import("@agoric/network").Bytes, _connectionHandler: import("@agoric/network").ConnectionHandler): Promise<string>;
|
|
72
|
+
onClose(_connection: import("@agoric/network").Connection, reason?: import("@agoric/network").CloseReason, _connectionHandler?: import("@agoric/network").ConnectionHandler): Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
listener: {
|
|
75
|
+
onAccept(_port: any, _localAddr: any, _remoteAddr: any, _listenHandler: any): Promise<Guarded<{
|
|
76
|
+
onReceive(_connection: import("@agoric/network").Connection, bytes: import("@agoric/network").Bytes, _connectionHandler: import("@agoric/network").ConnectionHandler): Promise<string>;
|
|
77
|
+
onClose(_connection: import("@agoric/network").Connection, reason?: import("@agoric/network").CloseReason, _connectionHandler?: import("@agoric/network").ConnectionHandler): Promise<void>;
|
|
78
|
+
}>>;
|
|
79
|
+
onListen(port: any, _listenHandler: any): Promise<void>;
|
|
80
|
+
};
|
|
81
|
+
}>;
|
|
82
|
+
unregisterProtocolHandler: (prefix: any, handler: any) => void;
|
|
83
|
+
getPortAllocator: () => Guarded<{
|
|
84
|
+
allocateCustomIBCPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
85
|
+
allocateICAControllerPort(): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
86
|
+
allocateICQControllerPort(): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
87
|
+
allocateCustomLocalPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
88
|
+
}>;
|
|
89
|
+
} & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
90
|
+
registerProtocolHandler: (prefixes: any, handler: any) => void;
|
|
91
|
+
makeLoopbackProtocolHandler: (instancePrefix?: string) => Guarded<{
|
|
92
|
+
onCreate(_impl: any, _protocolHandler: any): Promise<void>;
|
|
93
|
+
generatePortID(_localAddr: any, _protocolHandler: any): Promise<string>;
|
|
94
|
+
onBind(_port: any, _localAddr: any, _protocolHandler: any): Promise<void>;
|
|
95
|
+
onConnect(_port: any, localAddr: import("@agoric/network").Endpoint, remoteAddr: import("@agoric/network").Endpoint): import("@agoric/vow").PromiseVow<import("@agoric/network").AttemptDescription>;
|
|
96
|
+
onInstantiate(_port: any, _localAddr: any, _remote: any, _protocol: any): Promise<string>;
|
|
97
|
+
onListen(port: any, localAddr: any, listenHandler: any, _protocolHandler: any): Promise<void>;
|
|
98
|
+
onListenRemove(port: import("@agoric/vow").Remote<import("@agoric/network").Port>, localAddr: import("@agoric/network").Endpoint, listenHandler: import("@agoric/vow").Remote<import("@agoric/network").ListenHandler>, _protocolHandler: any): Promise<void>;
|
|
99
|
+
onRevoke(_port: any, _localAddr: any, _protocolHandler: any): Promise<void>;
|
|
100
|
+
}>;
|
|
101
|
+
makeEchoConnectionKit: () => import("@endo/exo").GuardedKit<{
|
|
102
|
+
handler: {
|
|
103
|
+
onReceive(_connection: import("@agoric/network").Connection, bytes: import("@agoric/network").Bytes, _connectionHandler: import("@agoric/network").ConnectionHandler): Promise<string>;
|
|
104
|
+
onClose(_connection: import("@agoric/network").Connection, reason?: import("@agoric/network").CloseReason, _connectionHandler?: import("@agoric/network").ConnectionHandler): Promise<void>;
|
|
105
|
+
};
|
|
106
|
+
listener: {
|
|
107
|
+
onAccept(_port: any, _localAddr: any, _remoteAddr: any, _listenHandler: any): Promise<Guarded<{
|
|
108
|
+
onReceive(_connection: import("@agoric/network").Connection, bytes: import("@agoric/network").Bytes, _connectionHandler: import("@agoric/network").ConnectionHandler): Promise<string>;
|
|
109
|
+
onClose(_connection: import("@agoric/network").Connection, reason?: import("@agoric/network").CloseReason, _connectionHandler?: import("@agoric/network").ConnectionHandler): Promise<void>;
|
|
110
|
+
}>>;
|
|
111
|
+
onListen(port: any, _listenHandler: any): Promise<void>;
|
|
112
|
+
};
|
|
113
|
+
}>;
|
|
114
|
+
unregisterProtocolHandler: (prefix: any, handler: any) => void;
|
|
115
|
+
getPortAllocator: () => Guarded<{
|
|
116
|
+
allocateCustomIBCPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
117
|
+
allocateICAControllerPort(): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
118
|
+
allocateICQControllerPort(): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
119
|
+
allocateCustomLocalPort(specifiedName?: string): Promise<import("@agoric/vow").Vow<import("@agoric/network").Port>>;
|
|
120
|
+
}>;
|
|
121
|
+
}>;
|
|
122
|
+
ibcVat: {
|
|
123
|
+
makeCallbacks: (dibcBridgeManager: import("@agoric/vats").ScopedBridgeManager<"dibc">) => Guarded<{
|
|
124
|
+
downcall(method: string, obj: any): Promise<any>;
|
|
125
|
+
}>;
|
|
126
|
+
createHandlers(callbacks: any): {
|
|
127
|
+
protocolHandler: import("@agoric/network").ProtocolHandler;
|
|
128
|
+
bridgeHandler: import("@agoric/vats").BridgeHandler;
|
|
129
|
+
};
|
|
130
|
+
} & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
131
|
+
makeCallbacks: (dibcBridgeManager: import("@agoric/vats").ScopedBridgeManager<"dibc">) => Guarded<{
|
|
132
|
+
downcall(method: string, obj: any): Promise<any>;
|
|
133
|
+
}>;
|
|
134
|
+
createHandlers(callbacks: any): {
|
|
135
|
+
protocolHandler: import("@agoric/network").ProtocolHandler;
|
|
136
|
+
bridgeHandler: import("@agoric/vats").BridgeHandler;
|
|
137
|
+
};
|
|
138
|
+
}>;
|
|
139
|
+
setupIBCProtocol: () => Promise<void>;
|
|
140
|
+
};
|
|
141
|
+
export {};
|
|
142
|
+
//# sourceMappingURL=network-fakes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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,CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,IAAI,KACT,OAAO,CACR,0BAA0B,CAAC,MAAM,CAAC,GAAG;IACnC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IACzD,gBAAgB,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,iBAAiB,EAAE,MAAM;QACvB,YAAY,EAAE,YAAY,CAAC;QAC3B,eAAe,EAAE,eAAe,CAAC;KAClC,CAAC;CACH,CAkKF,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,MAAM,IAAI,EACV,cAAc;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE;;;;;;;;;;;;;oBA7KtB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI;oBAC1C,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI;0BACtC,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI;2BAC9B,MAAM;YACvB,YAAY,EAAE,YAAY,CAAC;YAC3B,eAAe,EAAE,eAAe,CAAC;SAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4NJ,CAAC"}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
|
|
3
|
+
import type { VowTools } from '@agoric/vow';
|
|
4
|
+
import {
|
|
5
|
+
base64ToBytes,
|
|
6
|
+
prepareEchoConnectionKit,
|
|
7
|
+
prepareLoopbackProtocolHandler,
|
|
8
|
+
prepareNetworkPowers,
|
|
9
|
+
preparePortAllocator,
|
|
10
|
+
prepareRouterProtocol,
|
|
11
|
+
} from '@agoric/network';
|
|
12
|
+
import type { Zone } from '@agoric/zone';
|
|
13
|
+
import type {
|
|
14
|
+
IBCChannelID,
|
|
15
|
+
IBCMethod,
|
|
16
|
+
IBCEvent,
|
|
17
|
+
ScopedBridgeManagerMethods,
|
|
18
|
+
IBCConnectionID,
|
|
19
|
+
IBCPortID,
|
|
20
|
+
} from '@agoric/vats';
|
|
21
|
+
import {
|
|
22
|
+
prepareCallbacks as prepareIBCCallbacks,
|
|
23
|
+
prepareIBCProtocol,
|
|
24
|
+
} from '@agoric/vats/src/ibc.js';
|
|
25
|
+
import { BridgeId, makeTracer } from '@agoric/internal';
|
|
26
|
+
import { E, Far } from '@endo/far';
|
|
27
|
+
import type { Guarded } from '@endo/exo';
|
|
28
|
+
import {
|
|
29
|
+
defaultMockAckMap,
|
|
30
|
+
errorAcknowledgments,
|
|
31
|
+
} from './ibc-mock-fixtures.js';
|
|
32
|
+
import { decodeProtobufBase64 } from './protobuf-decoder.js';
|
|
33
|
+
|
|
34
|
+
const trace = makeTracer('NetworkFakes');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Mimic IBC Channel version negotiation
|
|
38
|
+
*
|
|
39
|
+
* As part of the IBC Channel initialization, the version field is negotiated
|
|
40
|
+
* with the host. `version` is a String or JSON string as determined by the IBC
|
|
41
|
+
* Application protocol.
|
|
42
|
+
*
|
|
43
|
+
* @param version requested version string
|
|
44
|
+
* @param params mock parameters to add to version string
|
|
45
|
+
* @param params.address for ICS-27, the bech32 address provided by the host
|
|
46
|
+
*/
|
|
47
|
+
const addParamsIfJsonVersion = (
|
|
48
|
+
version: string,
|
|
49
|
+
params: { address: string },
|
|
50
|
+
): string => {
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(version);
|
|
53
|
+
return JSON.stringify({
|
|
54
|
+
...parsed,
|
|
55
|
+
...params,
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
return version;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type ImplementedIBCEvents = 'channelOpenAck' | 'acknowledgementPacket';
|
|
63
|
+
|
|
64
|
+
export const ibcBridgeMocks: {
|
|
65
|
+
[T in ImplementedIBCEvents]: T extends 'channelOpenAck'
|
|
66
|
+
? (
|
|
67
|
+
obj: IBCMethod<'startChannelOpenInit'>,
|
|
68
|
+
opts: {
|
|
69
|
+
channelID: IBCChannelID;
|
|
70
|
+
counterpartyChannelID: IBCChannelID;
|
|
71
|
+
mockChainAddress: string;
|
|
72
|
+
},
|
|
73
|
+
) => IBCEvent<'channelOpenAck'>
|
|
74
|
+
: T extends 'acknowledgementPacket'
|
|
75
|
+
? (
|
|
76
|
+
obj: IBCMethod<'sendPacket'>,
|
|
77
|
+
opts: { sequence: bigint; acknowledgement: string },
|
|
78
|
+
) => IBCEvent<'acknowledgementPacket'>
|
|
79
|
+
: never;
|
|
80
|
+
} = {
|
|
81
|
+
channelOpenAck: (
|
|
82
|
+
obj: IBCMethod<'startChannelOpenInit'>,
|
|
83
|
+
{
|
|
84
|
+
channelID,
|
|
85
|
+
counterpartyChannelID,
|
|
86
|
+
mockChainAddress,
|
|
87
|
+
}: {
|
|
88
|
+
channelID: IBCChannelID;
|
|
89
|
+
counterpartyChannelID: IBCChannelID;
|
|
90
|
+
mockChainAddress: string;
|
|
91
|
+
},
|
|
92
|
+
): IBCEvent<'channelOpenAck'> => {
|
|
93
|
+
return {
|
|
94
|
+
type: 'IBC_EVENT',
|
|
95
|
+
blockHeight: 99,
|
|
96
|
+
blockTime: 1711571357,
|
|
97
|
+
event: 'channelOpenAck',
|
|
98
|
+
portID: obj.packet.source_port,
|
|
99
|
+
channelID,
|
|
100
|
+
counterparty: {
|
|
101
|
+
port_id: obj.packet.destination_port,
|
|
102
|
+
channel_id: counterpartyChannelID,
|
|
103
|
+
},
|
|
104
|
+
counterpartyVersion: addParamsIfJsonVersion(obj.version, {
|
|
105
|
+
address: mockChainAddress,
|
|
106
|
+
}),
|
|
107
|
+
connectionHops: obj.hops,
|
|
108
|
+
order: obj.order,
|
|
109
|
+
version: obj.version,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
acknowledgementPacket: (
|
|
114
|
+
obj: IBCMethod<'sendPacket'>,
|
|
115
|
+
opts: { sequence: bigint; acknowledgement: string },
|
|
116
|
+
): IBCEvent<'acknowledgementPacket'> => {
|
|
117
|
+
const { sequence, acknowledgement } = opts;
|
|
118
|
+
return {
|
|
119
|
+
acknowledgement,
|
|
120
|
+
blockHeight: 289,
|
|
121
|
+
blockTime: 1712180320,
|
|
122
|
+
event: 'acknowledgementPacket',
|
|
123
|
+
packet: {
|
|
124
|
+
data: obj.packet.data,
|
|
125
|
+
destination_channel: obj.packet.destination_channel,
|
|
126
|
+
destination_port: obj.packet.destination_port,
|
|
127
|
+
sequence: String(sequence),
|
|
128
|
+
source_channel: obj.packet.source_channel,
|
|
129
|
+
source_port: obj.packet.source_port,
|
|
130
|
+
timeout_timestamp: '1712183910866313000',
|
|
131
|
+
},
|
|
132
|
+
relayer: 'agoric1gtkg0g6x8lqc734ht3qe2sdkrfugpdp2h7fuu0',
|
|
133
|
+
type: 'IBC_EVENT',
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
type BridgeEvents = Array<
|
|
139
|
+
| IBCEvent<'channelOpenAck'>
|
|
140
|
+
| IBCEvent<'acknowledgementPacket'>
|
|
141
|
+
| IBCEvent<'channelCloseConfirm'>
|
|
142
|
+
| IBCEvent<'sendPacket'>
|
|
143
|
+
>;
|
|
144
|
+
|
|
145
|
+
type BridgeDowncalls = Array<
|
|
146
|
+
| IBCMethod<'startChannelOpenInit'>
|
|
147
|
+
| IBCMethod<'startChannelCloseInit'>
|
|
148
|
+
| IBCMethod<'bindPort'>
|
|
149
|
+
| IBCMethod<'sendPacket'>
|
|
150
|
+
>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Make a fake IBC Bridge, extended from the dibc ScopedBridgeManager.
|
|
154
|
+
*
|
|
155
|
+
* Has extra `setMockAck` and `setAddressPrefix` methods.
|
|
156
|
+
*
|
|
157
|
+
* @param zone
|
|
158
|
+
*/
|
|
159
|
+
export const makeFakeIBCBridge = (
|
|
160
|
+
zone: Zone,
|
|
161
|
+
): Guarded<
|
|
162
|
+
ScopedBridgeManagerMethods<'dibc'> & {
|
|
163
|
+
addMockAck: (msgData: string, ackData: string) => void;
|
|
164
|
+
setMockAck: (mockAckMap: Record<string, string>) => void;
|
|
165
|
+
setAddressPrefix: (addressPrefix: string) => void;
|
|
166
|
+
inspectDibcBridge: () => {
|
|
167
|
+
bridgeEvents: BridgeEvents;
|
|
168
|
+
bridgeDowncalls: BridgeDowncalls;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
> => {
|
|
172
|
+
let bridgeHandler: any;
|
|
173
|
+
/**
|
|
174
|
+
* Intended to mock an individual account's sequence, but is global for all
|
|
175
|
+
* accounts.
|
|
176
|
+
* XXX teach this about IBCConnections and store sequence on a
|
|
177
|
+
* per-channel basis.
|
|
178
|
+
*/
|
|
179
|
+
let ibcSequenceNonce = 0n;
|
|
180
|
+
/**
|
|
181
|
+
* The number of channels created. Currently used as a proxy to increment
|
|
182
|
+
* fake account addresses and channels.
|
|
183
|
+
*/
|
|
184
|
+
let channelCount = 0;
|
|
185
|
+
let icaAccountCount = 0;
|
|
186
|
+
let bech32Prefix = 'cosmos';
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Keep track channels requested by remote chain. Used as a proxy for
|
|
190
|
+
* counterparty channel ids.
|
|
191
|
+
*/
|
|
192
|
+
const remoteChannelMap: Record<IBCConnectionID, number> = {};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Packet byte string map of requests to responses
|
|
196
|
+
*/
|
|
197
|
+
let mockAckMap = defaultMockAckMap;
|
|
198
|
+
let bridgeEvents: BridgeEvents = [];
|
|
199
|
+
let bridgeDowncalls: BridgeDowncalls = [];
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Store remote mock addresses that have been distributed.
|
|
203
|
+
* If there's a `channelOpenInit` request for a PortId:ConnnectionId
|
|
204
|
+
* pair that's been previously established, let's reuse it to mimic
|
|
205
|
+
* the behavior of the ICS-27 protocol.
|
|
206
|
+
*/
|
|
207
|
+
type AddressKey = `${IBCPortID}:${IBCConnectionID}`;
|
|
208
|
+
const getAddressKey = (
|
|
209
|
+
obj: IBCMethod<'startChannelOpenInit'>,
|
|
210
|
+
): AddressKey => {
|
|
211
|
+
return `${obj.packet.source_port as IBCPortID}:${obj.hops[0] as IBCConnectionID}`;
|
|
212
|
+
};
|
|
213
|
+
const addressMap = new Map<AddressKey, string>();
|
|
214
|
+
|
|
215
|
+
return zone.exo('Fake IBC Bridge Manager', undefined, {
|
|
216
|
+
getBridgeId: () => BridgeId.DIBC,
|
|
217
|
+
toBridge: async obj => {
|
|
218
|
+
trace(
|
|
219
|
+
'toBridge',
|
|
220
|
+
obj,
|
|
221
|
+
obj.packet?.data ? base64ToBytes(obj.packet.data) : undefined,
|
|
222
|
+
);
|
|
223
|
+
if (obj.type === 'IBC_METHOD') {
|
|
224
|
+
bridgeDowncalls = bridgeDowncalls.concat(obj);
|
|
225
|
+
switch (obj.method) {
|
|
226
|
+
case 'startChannelOpenInit': {
|
|
227
|
+
const connectionChannelCount = remoteChannelMap[obj.hops[0]] || 0;
|
|
228
|
+
const addressKey = getAddressKey(obj);
|
|
229
|
+
let mockChainAddress;
|
|
230
|
+
if (addressMap.has(addressKey)) {
|
|
231
|
+
mockChainAddress = addressMap.get(addressKey);
|
|
232
|
+
} else {
|
|
233
|
+
mockChainAddress =
|
|
234
|
+
icaAccountCount > 0
|
|
235
|
+
? `${bech32Prefix}1test${icaAccountCount}`
|
|
236
|
+
: `${bech32Prefix}1test`;
|
|
237
|
+
addressMap.set(addressKey, mockChainAddress);
|
|
238
|
+
}
|
|
239
|
+
const ackEvent = ibcBridgeMocks.channelOpenAck(obj, {
|
|
240
|
+
mockChainAddress,
|
|
241
|
+
channelID: `channel-${channelCount}`,
|
|
242
|
+
counterpartyChannelID: `channel-${connectionChannelCount}`,
|
|
243
|
+
});
|
|
244
|
+
bridgeHandler?.fromBridge(ackEvent);
|
|
245
|
+
bridgeEvents = bridgeEvents.concat(ackEvent);
|
|
246
|
+
channelCount += 1;
|
|
247
|
+
if (obj.packet.source_port.includes('icacontroller')) {
|
|
248
|
+
icaAccountCount += 1;
|
|
249
|
+
}
|
|
250
|
+
remoteChannelMap[obj.hops[0]] = connectionChannelCount + 1;
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
case 'sendPacket': {
|
|
254
|
+
const mockAckMapHasData = obj.packet.data in mockAckMap;
|
|
255
|
+
if (!mockAckMapHasData) {
|
|
256
|
+
trace(
|
|
257
|
+
`sendPacket acking err because no mock ack for b64 data key: '${obj.packet.data}'`,
|
|
258
|
+
);
|
|
259
|
+
try {
|
|
260
|
+
const decoded = decodeProtobufBase64(
|
|
261
|
+
JSON.parse(base64ToBytes(obj.packet.data)).data,
|
|
262
|
+
);
|
|
263
|
+
trace(
|
|
264
|
+
'Fix the source of this request or define a ack mapping for it:',
|
|
265
|
+
inspect(decoded, { depth: null }),
|
|
266
|
+
);
|
|
267
|
+
} catch (err) {
|
|
268
|
+
trace('Could not decode packet data', err);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const ackEvent = ibcBridgeMocks.acknowledgementPacket(obj, {
|
|
272
|
+
sequence: ibcSequenceNonce,
|
|
273
|
+
acknowledgement: mockAckMapHasData
|
|
274
|
+
? mockAckMap[obj.packet.data]
|
|
275
|
+
: errorAcknowledgments.error5,
|
|
276
|
+
});
|
|
277
|
+
bridgeEvents = bridgeEvents.concat(ackEvent);
|
|
278
|
+
ibcSequenceNonce += 1n;
|
|
279
|
+
bridgeHandler?.fromBridge(ackEvent);
|
|
280
|
+
return ackEvent.packet;
|
|
281
|
+
}
|
|
282
|
+
default:
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return undefined;
|
|
287
|
+
},
|
|
288
|
+
fromBridge: async obj => {
|
|
289
|
+
trace('fromBridge', obj);
|
|
290
|
+
bridgeEvents = bridgeEvents.concat(obj);
|
|
291
|
+
if (!bridgeHandler) throw Error('no handler!');
|
|
292
|
+
return bridgeHandler.fromBridge(obj);
|
|
293
|
+
},
|
|
294
|
+
initHandler: handler => {
|
|
295
|
+
if (bridgeHandler) throw Error('already init');
|
|
296
|
+
bridgeHandler = handler;
|
|
297
|
+
},
|
|
298
|
+
setHandler: handler => {
|
|
299
|
+
if (!bridgeHandler) throw Error('must init first');
|
|
300
|
+
bridgeHandler = handler;
|
|
301
|
+
},
|
|
302
|
+
/**
|
|
303
|
+
* Set a map of requests to responses to simulate different scenarios. Defaults to `defaultMockAckMap`.
|
|
304
|
+
* See `@agoric/orchestration/tools/ibc-mocks.js` for helpers to build this map.
|
|
305
|
+
*
|
|
306
|
+
* @param ackMap
|
|
307
|
+
*/
|
|
308
|
+
setMockAck: (ackMap: typeof mockAckMap) => {
|
|
309
|
+
trace('setMockAck', ackMap);
|
|
310
|
+
mockAckMap = ackMap;
|
|
311
|
+
},
|
|
312
|
+
addMockAck: (msgData: string, ackData: string) => {
|
|
313
|
+
trace('addMockAck', msgData, ackData);
|
|
314
|
+
mockAckMap[msgData] = ackData;
|
|
315
|
+
},
|
|
316
|
+
/**
|
|
317
|
+
* Set a new bech32 prefix for the mocked ICA channel. Defaults to `cosmos`.
|
|
318
|
+
*
|
|
319
|
+
* @param newPrefix
|
|
320
|
+
*/
|
|
321
|
+
setAddressPrefix: (newPrefix: typeof bech32Prefix) => {
|
|
322
|
+
trace('setAddressPrefix', newPrefix);
|
|
323
|
+
bech32Prefix = newPrefix;
|
|
324
|
+
},
|
|
325
|
+
/**
|
|
326
|
+
* for debugging and testing
|
|
327
|
+
*/
|
|
328
|
+
inspectDibcBridge() {
|
|
329
|
+
return { bridgeEvents, bridgeDowncalls };
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
export const setupFakeNetwork = (
|
|
335
|
+
zone: Zone,
|
|
336
|
+
{ vowTools }: { vowTools: VowTools },
|
|
337
|
+
) => {
|
|
338
|
+
const powers = prepareNetworkPowers(zone, vowTools);
|
|
339
|
+
const makeRouterProtocol = prepareRouterProtocol(zone, powers);
|
|
340
|
+
const makePortAllocator = preparePortAllocator(zone, powers);
|
|
341
|
+
const makeLoopbackProtocolHandler = prepareLoopbackProtocolHandler(
|
|
342
|
+
zone,
|
|
343
|
+
vowTools,
|
|
344
|
+
);
|
|
345
|
+
const makeEchoConnectionKit = prepareEchoConnectionKit(zone);
|
|
346
|
+
const makeIBCProtocolHandler = prepareIBCProtocol(zone, vowTools);
|
|
347
|
+
|
|
348
|
+
const protocol = makeRouterProtocol();
|
|
349
|
+
const portAllocator = makePortAllocator({ protocol });
|
|
350
|
+
const ibcBridge = makeFakeIBCBridge(zone);
|
|
351
|
+
|
|
352
|
+
const networkVat = Far('vat-network', {
|
|
353
|
+
registerProtocolHandler: (prefixes, handler) =>
|
|
354
|
+
protocol.registerProtocolHandler(prefixes, handler),
|
|
355
|
+
makeLoopbackProtocolHandler,
|
|
356
|
+
makeEchoConnectionKit,
|
|
357
|
+
unregisterProtocolHandler: (prefix, handler) =>
|
|
358
|
+
protocol.unregisterProtocolHandler(prefix, handler),
|
|
359
|
+
getPortAllocator: () => portAllocator,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
const ibcVat = Far('vat-ibc', {
|
|
363
|
+
makeCallbacks: prepareIBCCallbacks(zone),
|
|
364
|
+
createHandlers(callbacks) {
|
|
365
|
+
const ibcHandler = makeIBCProtocolHandler(callbacks);
|
|
366
|
+
return harden(ibcHandler);
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const setupIBCProtocol = async () => {
|
|
371
|
+
const callbacks = await E(ibcVat).makeCallbacks(ibcBridge);
|
|
372
|
+
const { protocolHandler, bridgeHandler } =
|
|
373
|
+
await E(ibcVat).createHandlers(callbacks);
|
|
374
|
+
await E(ibcBridge).initHandler(bridgeHandler);
|
|
375
|
+
await E(networkVat).registerProtocolHandler(
|
|
376
|
+
['/ibc-port', '/ibc-hop'],
|
|
377
|
+
protocolHandler,
|
|
378
|
+
);
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
portAllocator,
|
|
383
|
+
protocol,
|
|
384
|
+
ibcBridge,
|
|
385
|
+
networkVat,
|
|
386
|
+
ibcVat,
|
|
387
|
+
setupIBCProtocol,
|
|
388
|
+
};
|
|
389
|
+
};
|