Skip to content

Commit

Permalink
test(api): policies tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hbriese committed Jul 28, 2024
1 parent 422de4f commit 54ee816
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 445 deletions.
142 changes: 71 additions & 71 deletions api/dbschema/edgeql-js/__spec__.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/dbschema/edgeql-js/modules/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type $AbstractConfigλShape = $.typeutil.flatten<$ConfigObjectλShape & {
"default_statistics_target": $.PropertyDesc<_std.$int64, $.Cardinality.AtMostOne, false, false, false, false>;
"force_database_error": $.PropertyDesc<_std.$str, $.Cardinality.AtMostOne, false, false, false, true>;
"_pg_prepared_statement_cache_size": $.PropertyDesc<_std.$int16, $.Cardinality.One, false, false, false, true>;
"auto_rebuild_query_cache_timeout": $.PropertyDesc<_std.$duration, $.Cardinality.AtMostOne, false, false, false, true>;
"<cfg[is cfg::ExtensionConfig]": $.LinkDesc<$ExtensionConfig, $.Cardinality.AtMostOne, {}, true, false, false, false>;
"<cfg": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
}>;
Expand Down
146 changes: 73 additions & 73 deletions api/dbschema/edgeql-js/modules/default.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/dbschema/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export namespace cfg {
"default_statistics_target"?: number | null;
"force_database_error"?: string | null;
"_pg_prepared_statement_cache_size": number;
"auto_rebuild_query_cache_timeout"?: edgedb.Duration | null;
}
export type AllowBareDDL = "AlwaysAllow" | "NeverAllow";
export interface Auth extends ConfigObject {
Expand Down
6 changes: 5 additions & 1 deletion api/src/feat/accounts/accounts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ export class AccountsService {
}),
);

await this.policies.propose({ account: address, policies: selfRefPolicies }, true);
await this.policies.propose({
account: address,
policies: selfRefPolicies,
isInitialization: true,
});
});

this.contracts.addAccountAsVerified(asAddress(address));
Expand Down
12 changes: 8 additions & 4 deletions api/src/feat/policies/insert-policies.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ with account := (select Account filter .address = <UAddress>$account),
txId := <optional uuid>$transaction,
tx := ((select Transaction filter .id = txId) if exists txId else {})
for p in array_unpack(<array<json>>$policies) union (
insert Policy {
with policy := (insert Policy {
account := account,
key := <uint16>p['key'],
proposal := tx,
activationBlock := <bigint><str>p['activationBlock'],
activationBlock := <bigint><str>json_get(p, 'activationBlock'),
name := <str>p['name'],
threshold := <uint16>p['threshold'],
approvers := (
Expand Down Expand Up @@ -39,17 +39,21 @@ for p in array_unpack(<array<json>>$policies) union (
defaultAllow := <bool>p['transfers']['defaultAllow'],
budget := <uint32>p['transfers']['budget'],
limits := (
for l in array_unpack(<array<json>>json_get(p, 'transfers.limits')) union (
for l in array_unpack(<array<json>>json_get(p, 'transfers', 'limits')) union (
insert TransferLimit {
token := <Address>l['token'],
amount := <uint224><str>l['amount'],
duration := <uint32><str>l['duration'],
duration := <uint32>l['duration'],
}
)
),
}
),
allowMessages := <bool>json_get(p, 'allowMessages'),
delay := <uint32>json_get(p, 'delay'),
})
select policy {
id,
key
}
)
13 changes: 9 additions & 4 deletions api/src/feat/policies/insert-policies.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type InsertPoliciesArgs = {

export type InsertPoliciesReturns = Array<{
"id": string;
"key": number;
}>;

export function insertPolicies(client: Executor, args: InsertPoliciesArgs): Promise<InsertPoliciesReturns> {
Expand All @@ -18,11 +19,11 @@ with account := (select Account filter .address = <UAddress>$account),
txId := <optional uuid>$transaction,
tx := ((select Transaction filter .id = txId) if exists txId else {})
for p in array_unpack(<array<json>>$policies) union (
insert Policy {
with policy := (insert Policy {
account := account,
key := <uint16>p['key'],
proposal := tx,
activationBlock := <bigint><str>p['activationBlock'],
activationBlock := <bigint><str>json_get(p, 'activationBlock'),
name := <str>p['name'],
threshold := <uint16>p['threshold'],
approvers := (
Expand Down Expand Up @@ -55,18 +56,22 @@ for p in array_unpack(<array<json>>$policies) union (
defaultAllow := <bool>p['transfers']['defaultAllow'],
budget := <uint32>p['transfers']['budget'],
limits := (
for l in array_unpack(<array<json>>json_get(p, 'transfers.limits')) union (
for l in array_unpack(<array<json>>json_get(p, 'transfers', 'limits')) union (
insert TransferLimit {
token := <Address>l['token'],
amount := <uint224><str>l['amount'],
duration := <uint32><str>l['duration'],
duration := <uint32>l['duration'],
}
)
),
}
),
allowMessages := <bool>json_get(p, 'allowMessages'),
delay := <uint32>json_get(p, 'delay'),
})
select policy {
id,
key
}
)`, args);

Expand Down
Loading

0 comments on commit 54ee816

Please sign in to comment.