Skip to content

Commit

Permalink
feat(undelegate): use Timestamp instead of Date (#9646)
Browse files Browse the repository at this point in the history
refs: #9042

## Description

This PR primarily improves unit testing around the `.undelegate()` flow and was motivated by a failure (inability to decode `completionTime`) discovered in E2E testing. 

- Add tests for cosmos-orchestration-account staking flows using mocked IBC messages
- Use `Timestamp` (from [google/protobuf/timestamp.proto](https://buf.build/protocolbuffers/wellknowntypes/docs/657250e6a39648cbb169d079a60bd9ba:google.protobuf#google.protobuf.Timestamp)) instead of `Date` for `@agoric/cosmic-proto` codegen for better endo compatibility
- Update `undelegate()` to use Timestamp for `wakeAt()` calculation

### Testing Considerations
This PR includes additional tests for cosmos-orchestration-account flows.

### Upgrade Considerations
This is a breaking change for `@agoric/cosmic-proto`, but not for the `agoric` namespace.
  • Loading branch information
mergify[bot] authored Jul 3, 2024
2 parents 00afafb + 3d4ab30 commit c2222f8
Show file tree
Hide file tree
Showing 31 changed files with 689 additions and 537 deletions.
5 changes: 5 additions & 0 deletions packages/boot/test/bootstrapTests/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ test.serial('stakeAtom - smart wallet', async t => {
);
});

test.todo('undelegate wallet offer');
test.todo('undelegate with multiple undelegations wallet offer');
test.todo('redelegate wallet offer');
test.todo('withdraw reward wallet offer');

// XXX rely on .serial to be in sequence, and keep this one last
test.serial('revise chain info', async t => {
const {
Expand Down
1 change: 1 addition & 0 deletions packages/cosmic-proto/scripts/codegen.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ telescope({
},
typingsFormat: {
useDeepPartial: false,
timestamp: 'timestamp',

// [Defaults]
// timestamp: 'date',
Expand Down
52 changes: 23 additions & 29 deletions packages/cosmic-proto/src/codegen/cosmos/authz/v1beta1/authz.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@ts-nocheck
import { Any, AnySDKType } from '../../../google/protobuf/any.js';
import { Timestamp } from '../../../google/protobuf/timestamp.js';
import {
Timestamp,
TimestampSDKType,
} from '../../../google/protobuf/timestamp.js';
import {
SendAuthorization,
SendAuthorizationSDKType,
Expand All @@ -14,12 +17,7 @@ import {
TransferAuthorizationSDKType,
} from '../../../ibc/applications/transfer/v1/authz.js';
import { BinaryReader, BinaryWriter } from '../../../binary.js';
import {
isSet,
toTimestamp,
fromTimestamp,
fromJsonTimestamp,
} from '../../../helpers.js';
import { isSet, fromJsonTimestamp, fromTimestamp } from '../../../helpers.js';
import { JsonSafe } from '../../../json-safe.js';
/**
* GenericAuthorization gives the grantee unrestricted permissions to execute
Expand Down Expand Up @@ -59,7 +57,7 @@ export interface Grant {
* doesn't have a time expiration (other conditions in `authorization`
* may apply to invalidate the grant)
*/
expiration?: Date;
expiration?: Timestamp;
}
export interface GrantProtoMsg {
typeUrl: '/cosmos.authz.v1beta1.Grant';
Expand All @@ -77,7 +75,7 @@ export interface GrantSDKType {
| TransferAuthorizationSDKType
| AnySDKType
| undefined;
expiration?: Date;
expiration?: TimestampSDKType;
}
/**
* GrantAuthorization extends a grant with both the addresses of the grantee and granter.
Expand All @@ -93,7 +91,7 @@ export interface GrantAuthorization {
TransferAuthorization &
Any)
| undefined;
expiration?: Date;
expiration?: Timestamp;
}
export interface GrantAuthorizationProtoMsg {
typeUrl: '/cosmos.authz.v1beta1.GrantAuthorization';
Expand All @@ -113,7 +111,7 @@ export interface GrantAuthorizationSDKType {
| TransferAuthorizationSDKType
| AnySDKType
| undefined;
expiration?: Date;
expiration?: TimestampSDKType;
}
/** GrantQueueItem contains the list of TypeURL of a sdk.Msg. */
export interface GrantQueueItem {
Expand Down Expand Up @@ -213,10 +211,7 @@ export const Grant = {
).ldelim();
}
if (message.expiration !== undefined) {
Timestamp.encode(
toTimestamp(message.expiration),
writer.uint32(18).fork(),
).ldelim();
Timestamp.encode(message.expiration, writer.uint32(18).fork()).ldelim();
}
return writer;
},
Expand All @@ -232,9 +227,7 @@ export const Grant = {
message.authorization = Authorization_InterfaceDecoder(reader) as Any;
break;
case 2:
message.expiration = fromTimestamp(
Timestamp.decode(reader, reader.uint32()),
);
message.expiration = Timestamp.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
Expand All @@ -260,7 +253,7 @@ export const Grant = {
? Any.toJSON(message.authorization)
: undefined);
message.expiration !== undefined &&
(obj.expiration = message.expiration.toISOString());
(obj.expiration = fromTimestamp(message.expiration).toISOString());
return obj;
},
fromPartial(object: Partial<Grant>): Grant {
Expand All @@ -269,7 +262,10 @@ export const Grant = {
object.authorization !== undefined && object.authorization !== null
? Any.fromPartial(object.authorization)
: undefined;
message.expiration = object.expiration ?? undefined;
message.expiration =
object.expiration !== undefined && object.expiration !== null
? Timestamp.fromPartial(object.expiration)
: undefined;
return message;
},
fromProtoMsg(message: GrantProtoMsg): Grant {
Expand Down Expand Up @@ -312,10 +308,7 @@ export const GrantAuthorization = {
).ldelim();
}
if (message.expiration !== undefined) {
Timestamp.encode(
toTimestamp(message.expiration),
writer.uint32(34).fork(),
).ldelim();
Timestamp.encode(message.expiration, writer.uint32(34).fork()).ldelim();
}
return writer;
},
Expand All @@ -340,9 +333,7 @@ export const GrantAuthorization = {
message.authorization = Authorization_InterfaceDecoder(reader) as Any;
break;
case 4:
message.expiration = fromTimestamp(
Timestamp.decode(reader, reader.uint32()),
);
message.expiration = Timestamp.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
Expand Down Expand Up @@ -372,7 +363,7 @@ export const GrantAuthorization = {
? Any.toJSON(message.authorization)
: undefined);
message.expiration !== undefined &&
(obj.expiration = message.expiration.toISOString());
(obj.expiration = fromTimestamp(message.expiration).toISOString());
return obj;
},
fromPartial(object: Partial<GrantAuthorization>): GrantAuthorization {
Expand All @@ -383,7 +374,10 @@ export const GrantAuthorization = {
object.authorization !== undefined && object.authorization !== null
? Any.fromPartial(object.authorization)
: undefined;
message.expiration = object.expiration ?? undefined;
message.expiration =
object.expiration !== undefined && object.expiration !== null
? Timestamp.fromPartial(object.expiration)
: undefined;
return message;
},
fromProtoMsg(message: GrantAuthorizationProtoMsg): GrantAuthorization {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
//@ts-nocheck
import { Coin, CoinSDKType } from '../../base/v1beta1/coin.js';
import { Timestamp } from '../../../google/protobuf/timestamp.js';
import {
Timestamp,
TimestampSDKType,
} from '../../../google/protobuf/timestamp.js';
import {
Duration,
DurationSDKType,
} from '../../../google/protobuf/duration.js';
import { Any, AnySDKType } from '../../../google/protobuf/any.js';
import { BinaryReader, BinaryWriter } from '../../../binary.js';
import {
toTimestamp,
fromTimestamp,
isSet,
fromJsonTimestamp,
} from '../../../helpers.js';
import { isSet, fromJsonTimestamp, fromTimestamp } from '../../../helpers.js';
import { JsonSafe } from '../../../json-safe.js';
/**
* BasicAllowance implements Allowance with a one-time grant of coins
Expand All @@ -27,7 +25,7 @@ export interface BasicAllowance {
*/
spendLimit: Coin[];
/** expiration specifies an optional time when this allowance expires */
expiration?: Date;
expiration?: Timestamp;
}
export interface BasicAllowanceProtoMsg {
typeUrl: '/cosmos.feegrant.v1beta1.BasicAllowance';
Expand All @@ -40,7 +38,7 @@ export interface BasicAllowanceProtoMsg {
export interface BasicAllowanceSDKType {
$typeUrl?: '/cosmos.feegrant.v1beta1.BasicAllowance';
spend_limit: CoinSDKType[];
expiration?: Date;
expiration?: TimestampSDKType;
}
/**
* PeriodicAllowance extends Allowance to allow for both a maximum cap,
Expand All @@ -67,7 +65,7 @@ export interface PeriodicAllowance {
* it is calculated from the start time of the first transaction after the
* last period ended
*/
periodReset: Date;
periodReset: Timestamp;
}
export interface PeriodicAllowanceProtoMsg {
typeUrl: '/cosmos.feegrant.v1beta1.PeriodicAllowance';
Expand All @@ -83,7 +81,7 @@ export interface PeriodicAllowanceSDKType {
period: DurationSDKType;
period_spend_limit: CoinSDKType[];
period_can_spend: CoinSDKType[];
period_reset: Date;
period_reset: TimestampSDKType;
}
/** AllowedMsgAllowance creates allowance only for specified message types. */
export interface AllowedMsgAllowance {
Expand Down Expand Up @@ -153,10 +151,7 @@ export const BasicAllowance = {
Coin.encode(v!, writer.uint32(10).fork()).ldelim();
}
if (message.expiration !== undefined) {
Timestamp.encode(
toTimestamp(message.expiration),
writer.uint32(18).fork(),
).ldelim();
Timestamp.encode(message.expiration, writer.uint32(18).fork()).ldelim();
}
return writer;
},
Expand All @@ -172,9 +167,7 @@ export const BasicAllowance = {
message.spendLimit.push(Coin.decode(reader, reader.uint32()));
break;
case 2:
message.expiration = fromTimestamp(
Timestamp.decode(reader, reader.uint32()),
);
message.expiration = Timestamp.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
Expand Down Expand Up @@ -203,13 +196,16 @@ export const BasicAllowance = {
obj.spendLimit = [];
}
message.expiration !== undefined &&
(obj.expiration = message.expiration.toISOString());
(obj.expiration = fromTimestamp(message.expiration).toISOString());
return obj;
},
fromPartial(object: Partial<BasicAllowance>): BasicAllowance {
const message = createBaseBasicAllowance();
message.spendLimit = object.spendLimit?.map(e => Coin.fromPartial(e)) || [];
message.expiration = object.expiration ?? undefined;
message.expiration =
object.expiration !== undefined && object.expiration !== null
? Timestamp.fromPartial(object.expiration)
: undefined;
return message;
},
fromProtoMsg(message: BasicAllowanceProtoMsg): BasicAllowance {
Expand All @@ -232,7 +228,7 @@ function createBasePeriodicAllowance(): PeriodicAllowance {
period: Duration.fromPartial({}),
periodSpendLimit: [],
periodCanSpend: [],
periodReset: new Date(),
periodReset: Timestamp.fromPartial({}),
};
}
export const PeriodicAllowance = {
Expand All @@ -254,10 +250,7 @@ export const PeriodicAllowance = {
Coin.encode(v!, writer.uint32(34).fork()).ldelim();
}
if (message.periodReset !== undefined) {
Timestamp.encode(
toTimestamp(message.periodReset),
writer.uint32(42).fork(),
).ldelim();
Timestamp.encode(message.periodReset, writer.uint32(42).fork()).ldelim();
}
return writer;
},
Expand All @@ -282,9 +275,7 @@ export const PeriodicAllowance = {
message.periodCanSpend.push(Coin.decode(reader, reader.uint32()));
break;
case 5:
message.periodReset = fromTimestamp(
Timestamp.decode(reader, reader.uint32()),
);
message.periodReset = Timestamp.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
Expand Down Expand Up @@ -337,7 +328,7 @@ export const PeriodicAllowance = {
obj.periodCanSpend = [];
}
message.periodReset !== undefined &&
(obj.periodReset = message.periodReset.toISOString());
(obj.periodReset = fromTimestamp(message.periodReset).toISOString());
return obj;
},
fromPartial(object: Partial<PeriodicAllowance>): PeriodicAllowance {
Expand All @@ -354,7 +345,10 @@ export const PeriodicAllowance = {
object.periodSpendLimit?.map(e => Coin.fromPartial(e)) || [];
message.periodCanSpend =
object.periodCanSpend?.map(e => Coin.fromPartial(e)) || [];
message.periodReset = object.periodReset ?? undefined;
message.periodReset =
object.periodReset !== undefined && object.periodReset !== null
? Timestamp.fromPartial(object.periodReset)
: undefined;
return message;
},
fromProtoMsg(message: PeriodicAllowanceProtoMsg): PeriodicAllowance {
Expand Down
Loading

0 comments on commit c2222f8

Please sign in to comment.