Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement revokeDelegation(ByDelegator|ByProvider) #514

Merged
merged 14 commits into from
Sep 17, 2024

Conversation

mattheworris
Copy link
Contributor

@mattheworris mattheworris commented Sep 12, 2024

Description

As a consumer of the Gateway API, I want to be able to revoke a previously granted delegation

Should implement:

  • GET /account/accounts/revokeDelegation/{accountId}/{providerId}
    • (returns a revokeDelegationByDelegator encoded extrinsic that can be signed)
  • POST /account/accounts/revokeDelegation submits a signed extrinsic for execution

Closes #411

Solution

New endpoints were added to implement the desired functionality.

Steps to Verify:

  1. Execute ./scripts/account/restart-chain-docker.sh and make sure account-service is running. You will need to additionally run the following command to start the account service, or start it locally, as the restart-chain script no longer brings up account.
  • docker compose -f docker-compose.yaml -f docker-compose-e2e.account.yaml --profile e2e --profile account up -d
  1. Execute cd ./apps/account-api/test/setup/ && npm run test-revoke-e2e
  2. Verify that msa.DelegationRevoked event appears on the local node.
    Note: This will only work once and then the chain state needs to be restarted.

@mattheworris mattheworris self-assigned this Sep 16, 2024
@mattheworris mattheworris changed the title Post monorepo merge 411 revoke delegation revokeDelegation(ByDelegator|ByProvider) Sep 16, 2024
@mattheworris mattheworris changed the title revokeDelegation(ByDelegator|ByProvider) Implement revokeDelegation(ByDelegator|ByProvider) Sep 16, 2024
@mattheworris mattheworris marked this pull request as ready for review September 16, 2024 18:29
.markdownlint.json Outdated Show resolved Hide resolved
const { keypair } = users[1];
const accountId = keypair.address;
const getPath: string = `/v1/delegation/revokeDelegation/${accountId}/${providerId}`;
const response = await request(app.getHttpServer()).get(getPath).expect(200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could either:

  • add a separate test for (GET) /v1/delegation/revokeDelegation/:accountId/:providerId specifically, -OR-
  • add some expect statements here to validate the response payload, and continue on to POST

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant to the E2E test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs against the full service and confirms that the transaction exectues, which doesn't happen for the jest based e2e tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where it confirms that the transaction executes; it just calls the POST endpoint and returns at the end... I agree that's what our E2E tests should do eventually, but I think we're going to take another issue for that overhaul.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarification: the transaction can be verified on the chain. No, the code doesn't check for it.

signature: HexString,
): Promise<[SubmittableExtrinsic<'promise'>, HexString]> {
try {
const prefixedSignature: SignerResult = { id: 1, signature };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same as SpRuntimeMultiSignature ?

If that is the case then one other way we created these were like the following example

const proof = { Sr25519: u8aToHex(delegatorKeys.sign(u8aWrapBytes(payload.toU8a()))) };

@mattheworris mattheworris force-pushed the post-monorepo-merge-411-revokeDelegation branch from 1a14267 to 1b1919e Compare September 16, 2024 20:46
@mattheworris mattheworris enabled auto-merge (squash) September 16, 2024 21:39
@mattheworris mattheworris force-pushed the post-monorepo-merge-411-revokeDelegation branch from ed8f8e5 to 89046ac Compare September 16, 2024 22:43
@@ -1,7 +1,7 @@
// eslint-disable-next-line max-classes-per-file
import { ApiProperty } from '@nestjs/swagger';
import { IsHexadecimal, IsNotEmpty } from 'class-validator';
import { TransactionType } from '#account-lib';
import { TransactionType } from '#account-lib/types/enums';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a Dependency cycle. I think this is related to the indexing problems we saw previously when importing and the services were being included when not needed.

Copy link
Contributor

@aramikm aramikm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@mattheworris mattheworris merged commit 6e9ef49 into main Sep 17, 2024
13 checks passed
@mattheworris mattheworris deleted the post-monorepo-merge-411-revokeDelegation branch September 17, 2024 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

revokeDelegation(ByDelegator|ByProvider)
3 participants