Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit 3e612d0

Browse files
committed
test(api): policies tests
1 parent 422de4f commit 3e612d0

9 files changed

+468
-445
lines changed

api/dbschema/edgeql-js/__spec__.ts

+71-71
Large diffs are not rendered by default.

api/dbschema/edgeql-js/modules/cfg.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export type $AbstractConfigλShape = $.typeutil.flatten<$ConfigObjectλShape & {
6262
"default_statistics_target": $.PropertyDesc<_std.$int64, $.Cardinality.AtMostOne, false, false, false, false>;
6363
"force_database_error": $.PropertyDesc<_std.$str, $.Cardinality.AtMostOne, false, false, false, true>;
6464
"_pg_prepared_statement_cache_size": $.PropertyDesc<_std.$int16, $.Cardinality.One, false, false, false, true>;
65+
"auto_rebuild_query_cache_timeout": $.PropertyDesc<_std.$duration, $.Cardinality.AtMostOne, false, false, false, true>;
6566
"<cfg[is cfg::ExtensionConfig]": $.LinkDesc<$ExtensionConfig, $.Cardinality.AtMostOne, {}, true, false, false, false>;
6667
"<cfg": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
6768
}>;

api/dbschema/edgeql-js/modules/default.ts

+73-73
Large diffs are not rendered by default.

api/dbschema/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export namespace cfg {
3838
"default_statistics_target"?: number | null;
3939
"force_database_error"?: string | null;
4040
"_pg_prepared_statement_cache_size": number;
41+
"auto_rebuild_query_cache_timeout"?: edgedb.Duration | null;
4142
}
4243
export type AllowBareDDL = "AlwaysAllow" | "NeverAllow";
4344
export interface Auth extends ConfigObject {

api/src/feat/accounts/accounts.service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ export class AccountsService {
151151
}),
152152
);
153153

154-
await this.policies.propose({ account: address, policies: selfRefPolicies }, true);
154+
await this.policies.propose({
155+
account: address,
156+
policies: selfRefPolicies,
157+
isInitialization: true,
158+
});
155159
});
156160

157161
this.contracts.addAccountAsVerified(asAddress(address));

api/src/feat/policies/insert-policies.edgeql

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ with account := (select Account filter .address = <UAddress>$account),
22
txId := <optional uuid>$transaction,
33
tx := ((select Transaction filter .id = txId) if exists txId else {})
44
for p in array_unpack(<array<json>>$policies) union (
5-
insert Policy {
5+
with policy := (insert Policy {
66
account := account,
77
key := <uint16>p['key'],
88
proposal := tx,
9-
activationBlock := <bigint><str>p['activationBlock'],
9+
activationBlock := <bigint><str>json_get(p, 'activationBlock'),
1010
name := <str>p['name'],
1111
threshold := <uint16>p['threshold'],
1212
approvers := (
@@ -39,17 +39,21 @@ for p in array_unpack(<array<json>>$policies) union (
3939
defaultAllow := <bool>p['transfers']['defaultAllow'],
4040
budget := <uint32>p['transfers']['budget'],
4141
limits := (
42-
for l in array_unpack(<array<json>>json_get(p, 'transfers.limits')) union (
42+
for l in array_unpack(<array<json>>json_get(p, 'transfers', 'limits')) union (
4343
insert TransferLimit {
4444
token := <Address>l['token'],
4545
amount := <uint224><str>l['amount'],
46-
duration := <uint32><str>l['duration'],
46+
duration := <uint32>l['duration'],
4747
}
4848
)
4949
),
5050
}
5151
),
5252
allowMessages := <bool>json_get(p, 'allowMessages'),
5353
delay := <uint32>json_get(p, 'delay'),
54+
})
55+
select policy {
56+
id,
57+
key
5458
}
5559
)

api/src/feat/policies/insert-policies.query.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type InsertPoliciesArgs = {
1010

1111
export type InsertPoliciesReturns = Array<{
1212
"id": string;
13+
"key": number;
1314
}>;
1415

1516
export function insertPolicies(client: Executor, args: InsertPoliciesArgs): Promise<InsertPoliciesReturns> {
@@ -18,11 +19,11 @@ with account := (select Account filter .address = <UAddress>$account),
1819
txId := <optional uuid>$transaction,
1920
tx := ((select Transaction filter .id = txId) if exists txId else {})
2021
for p in array_unpack(<array<json>>$policies) union (
21-
insert Policy {
22+
with policy := (insert Policy {
2223
account := account,
2324
key := <uint16>p['key'],
2425
proposal := tx,
25-
activationBlock := <bigint><str>p['activationBlock'],
26+
activationBlock := <bigint><str>json_get(p, 'activationBlock'),
2627
name := <str>p['name'],
2728
threshold := <uint16>p['threshold'],
2829
approvers := (
@@ -55,18 +56,22 @@ for p in array_unpack(<array<json>>$policies) union (
5556
defaultAllow := <bool>p['transfers']['defaultAllow'],
5657
budget := <uint32>p['transfers']['budget'],
5758
limits := (
58-
for l in array_unpack(<array<json>>json_get(p, 'transfers.limits')) union (
59+
for l in array_unpack(<array<json>>json_get(p, 'transfers', 'limits')) union (
5960
insert TransferLimit {
6061
token := <Address>l['token'],
6162
amount := <uint224><str>l['amount'],
62-
duration := <uint32><str>l['duration'],
63+
duration := <uint32>l['duration'],
6364
}
6465
)
6566
),
6667
}
6768
),
6869
allowMessages := <bool>json_get(p, 'allowMessages'),
6970
delay := <uint32>json_get(p, 'delay'),
71+
})
72+
select policy {
73+
id,
74+
key
7075
}
7176
)`, args);
7277

0 commit comments

Comments
 (0)