-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathibc-mocks.ts
128 lines (122 loc) · 3.43 KB
/
ibc-mocks.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/** @file The mocks used in these tests */
import {
QueryBalanceRequest,
QueryBalanceResponse,
} from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js';
import {
MsgBeginRedelegate,
MsgBeginRedelegateResponse,
MsgDelegate,
MsgDelegateResponse,
MsgUndelegate,
MsgUndelegateResponse,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import {
MsgWithdrawDelegatorReward,
MsgWithdrawDelegatorRewardResponse,
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/tx.js';
import type { Timestamp } from '@agoric/cosmic-proto/google/protobuf/timestamp.js';
import {
MsgSend,
MsgSendResponse,
} from '@agoric/cosmic-proto/cosmos/bank/v1beta1/tx.js';
import {
buildMsgResponseString,
buildQueryResponseString,
buildMsgErrorString,
buildTxPacketString,
buildQueryPacketString,
createMockAckMap,
} from '../tools/ibc-mocks.js';
/**
* TODO: provide mappings to cosmos error codes (and module specific error codes)
* see https://github.com/Agoric/agoric-sdk/issues/9629 for more details about
* error messages over ibc
*/
export const errorAcknowledgments = {
error5: buildMsgErrorString(
'ABCI code: 5: error handling packet: see events for details',
),
};
const delegation = {
amount: {
denom: 'uatom',
amount: '10',
},
delegatorAddress: 'cosmos1test',
validatorAddress: 'cosmosvaloper1test',
};
const redelegation = {
delegatorAddress: 'cosmos1test',
validatorSrcAddress: 'cosmosvaloper1test',
validatorDstAddress: 'cosmosvaloper2test',
amount: {
denom: 'uatom',
amount: '10',
},
};
const bankSend = {
fromAddress: 'cosmos1test',
toAddress: 'cosmos99test',
amount: [{ denom: 'uatom', amount: '10' }],
};
const bankSendMulti = {
fromAddress: 'cosmos1test',
toAddress: 'cosmos99test',
amount: [
{ denom: 'uatom', amount: '10' },
{ denom: 'ibc/1234', amount: '10' },
],
};
export const UNBOND_PERIOD_SECONDS = 5n;
const getUnbondingTime = (): Timestamp => ({
seconds: UNBOND_PERIOD_SECONDS,
nanos: 0,
});
export const protoMsgMocks = {
delegate: {
msg: buildTxPacketString([MsgDelegate.toProtoMsg(delegation)]),
ack: buildMsgResponseString(MsgDelegateResponse, {}),
},
undelegate: {
msg: buildTxPacketString([MsgUndelegate.toProtoMsg(delegation)]),
ack: buildMsgResponseString(MsgUndelegateResponse, {
completionTime: getUnbondingTime(),
}),
},
redelegate: {
msg: buildTxPacketString([MsgBeginRedelegate.toProtoMsg(redelegation)]),
ack: buildMsgResponseString(MsgBeginRedelegateResponse, {
completionTime: getUnbondingTime(),
}),
},
withdrawReward: {
msg: buildTxPacketString([
MsgWithdrawDelegatorReward.toProtoMsg(delegation),
]),
ack: buildMsgResponseString(MsgWithdrawDelegatorRewardResponse, {
amount: [{ amount: '1', denom: 'uatom' }],
}),
},
queryBalance: {
msg: buildQueryPacketString([
QueryBalanceRequest.toProtoMsg({
address: 'cosmos1test',
denom: 'uatom',
}),
]),
ack: buildQueryResponseString(QueryBalanceResponse, {
balance: { amount: '0', denom: 'uatom' },
}),
},
bankSend: {
msg: buildTxPacketString([MsgSend.toProtoMsg(bankSend)]),
ack: buildMsgResponseString(MsgSendResponse, {}),
},
bankSendMulti: {
msg: buildTxPacketString([MsgSend.toProtoMsg(bankSendMulti)]),
ack: buildMsgResponseString(MsgSendResponse, {}),
},
};
export const defaultMockAckMap: Record<string, string> =
createMockAckMap(protoMsgMocks);