-
Notifications
You must be signed in to change notification settings - Fork 40
Bugfix/rm auth param names #2244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f174240
ensure invoke host function tx shows contract parameters
piyalbasu 08e9852
add test for fallback if contract spec retrieval fails
piyalbasu b99a551
do not show contract parameters for authorizations
piyalbasu 7c5933d
Merge commit 'c5b1ff2692ed52a1bae78da3f5ecea89e03d65f1' into bugfix/r…
piyalbasu e3c414a
add tests for create contract v1 and invoke contract
piyalbasu 19c8a68
add issuer for changeTrust op (#2246)
piyalbasu f927cda
Revert "add issuer for changeTrust op (#2246)" (#2247)
piyalbasu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
extension/src/popup/components/__tests__/AuthEntry.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| import React from "react"; | ||
| import { render, waitFor, screen, fireEvent } from "@testing-library/react"; | ||
| import { Address, Keypair, ScInt, StrKey, xdr } from "stellar-sdk"; | ||
|
|
||
| import { mockAccounts, TEST_PUBLIC_KEY, Wrapper } from "popup/__testHelpers__"; | ||
| import { AuthEntries } from "../AuthEntry"; | ||
| import * as internalApi from "@shared/api/internal"; | ||
| import { APPLICATION_STATE } from "@shared/constants/applicationState"; | ||
| import { | ||
| TESTNET_NETWORK_DETAILS, | ||
| DEFAULT_NETWORKS, | ||
| } from "@shared/constants/stellar"; | ||
| import { ROUTES } from "popup/constants/routes"; | ||
|
|
||
| describe("AuthEntry", () => { | ||
| afterAll(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| const getContractSpecSpy = jest | ||
| .spyOn(internalApi, "getContractSpec") | ||
| .mockImplementation(() => { | ||
| return Promise.resolve({ | ||
| definitions: { | ||
| create: { | ||
| properties: { | ||
| args: ["admin"], | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("renders auth entries for create contract v1", async () => { | ||
| const assetCode = "KHL1"; | ||
| const assetType = new xdr.AlphaNum4({ | ||
| assetCode: Buffer.from(assetCode), | ||
| issuer: Keypair.fromPublicKey(TEST_PUBLIC_KEY).xdrAccountId(), | ||
| }); | ||
|
|
||
| const args = new xdr.CreateContractArgs({ | ||
| contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAsset( | ||
| xdr.Asset.assetTypeCreditAlphanum4(assetType), | ||
| ), | ||
| executable: xdr.ContractExecutable.contractExecutableStellarAsset(), | ||
| }); | ||
|
|
||
| const authorizedFn = | ||
| xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeCreateContractHostFn( | ||
| args, | ||
| ); | ||
| const authorizedInvocation = new xdr.SorobanAuthorizedInvocation({ | ||
| function: authorizedFn, | ||
| subInvocations: [], | ||
| }); | ||
|
|
||
| render( | ||
| <Wrapper | ||
| routes={[ROUTES.reviewAuthorization]} | ||
| state={{ | ||
| auth: { | ||
| error: null, | ||
| applicationState: APPLICATION_STATE.PASSWORD_CREATED, | ||
| TEST_PUBLIC_KEY, | ||
| allAccounts: mockAccounts, | ||
| hasPrivateKey: true, | ||
| }, | ||
| settings: { | ||
| networkDetails: TESTNET_NETWORK_DETAILS, | ||
| networksList: DEFAULT_NETWORKS, | ||
| isSorobanPublicEnabled: true, | ||
| isRpcHealthy: true, | ||
| }, | ||
| }} | ||
| > | ||
| <AuthEntries invocations={[authorizedInvocation]} /> | ||
| </Wrapper>, | ||
| ); | ||
| await waitFor(() => screen.getAllByTestId("AuthEntryContainer")); | ||
| await fireEvent.click(screen.getByTestId("AuthEntryBtn")); | ||
| await waitFor(() => screen.getAllByTestId("AuthEntryContent")); | ||
|
|
||
| expect(screen.getByTestId("AuthEntryBtn__Title")).toHaveTextContent( | ||
| "Contract creation", | ||
| ); | ||
|
|
||
| expect(getContractSpecSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("renders auth entries for create contract v2", async () => { | ||
| const assetCode = "KHL1"; | ||
| const assetType = new xdr.AlphaNum4({ | ||
| assetCode: Buffer.from(assetCode), | ||
| issuer: Keypair.fromPublicKey(TEST_PUBLIC_KEY).xdrAccountId(), | ||
| }); | ||
|
|
||
| const args = new xdr.CreateContractArgsV2({ | ||
| contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAsset( | ||
| xdr.Asset.assetTypeCreditAlphanum4(assetType), | ||
| ), | ||
| executable: xdr.ContractExecutable.contractExecutableStellarAsset(), | ||
| constructorArgs: [new Address(TEST_PUBLIC_KEY).toScVal()], | ||
| }); | ||
|
|
||
| const authorizedFn = | ||
| xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeCreateContractV2HostFn( | ||
| args, | ||
| ); | ||
| const authorizedInvocation = new xdr.SorobanAuthorizedInvocation({ | ||
| function: authorizedFn, | ||
| subInvocations: [], | ||
| }); | ||
|
|
||
| render( | ||
| <Wrapper | ||
| routes={[ROUTES.reviewAuthorization]} | ||
| state={{ | ||
| auth: { | ||
| error: null, | ||
| applicationState: APPLICATION_STATE.PASSWORD_CREATED, | ||
| TEST_PUBLIC_KEY, | ||
| allAccounts: mockAccounts, | ||
| hasPrivateKey: true, | ||
| }, | ||
| settings: { | ||
| networkDetails: TESTNET_NETWORK_DETAILS, | ||
| networksList: DEFAULT_NETWORKS, | ||
| isSorobanPublicEnabled: true, | ||
| isRpcHealthy: true, | ||
| }, | ||
| }} | ||
| > | ||
| <AuthEntries invocations={[authorizedInvocation]} /> | ||
| </Wrapper>, | ||
| ); | ||
| await waitFor(() => screen.getAllByTestId("AuthEntryContainer")); | ||
| await fireEvent.click(screen.getByTestId("AuthEntryBtn")); | ||
| await waitFor(() => screen.getAllByTestId("AuthEntryContent")); | ||
|
|
||
| expect(screen.getByTestId("AuthEntryBtn__Title")).toHaveTextContent( | ||
| "Contract creation", | ||
| ); | ||
|
|
||
| expect(getContractSpecSpy).not.toHaveBeenCalled(); | ||
|
|
||
| const parameterKeys = screen.getAllByTestId("ParameterKey"); | ||
| const parameterValues = screen.getAllByTestId("ParameterValue"); | ||
|
|
||
| expect(parameterKeys).toHaveLength(1); | ||
| expect(parameterKeys[0]).toHaveTextContent(""); | ||
|
|
||
| expect(parameterValues).toHaveLength(1); | ||
| expect(parameterValues[0]).toHaveTextContent(TEST_PUBLIC_KEY); | ||
| }); | ||
|
|
||
| it("renders auth entries for invoke contract args", async () => { | ||
| const CONTRACT = "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE"; | ||
| const args = new xdr.InvokeContractArgs({ | ||
| functionName: Buffer.from("transfer"), | ||
| args: [ | ||
| new Address(TEST_PUBLIC_KEY).toScVal(), | ||
| new Address(TEST_PUBLIC_KEY).toScVal(), | ||
| new ScInt(100).toI128(), | ||
| ], | ||
| contractAddress: xdr.ScAddress.scAddressTypeContract( | ||
| StrKey.decodeContract(CONTRACT) as any, | ||
| ), | ||
| }); | ||
|
|
||
| const authorizedFn = | ||
| xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn( | ||
| args, | ||
| ); | ||
| const authorizedInvocation = new xdr.SorobanAuthorizedInvocation({ | ||
| function: authorizedFn, | ||
| subInvocations: [], | ||
| }); | ||
|
|
||
| render( | ||
| <Wrapper | ||
| routes={[ROUTES.reviewAuthorization]} | ||
| state={{ | ||
| auth: { | ||
| error: null, | ||
| applicationState: APPLICATION_STATE.PASSWORD_CREATED, | ||
| TEST_PUBLIC_KEY, | ||
| allAccounts: mockAccounts, | ||
| hasPrivateKey: true, | ||
| }, | ||
| settings: { | ||
| networkDetails: TESTNET_NETWORK_DETAILS, | ||
| networksList: DEFAULT_NETWORKS, | ||
| isSorobanPublicEnabled: true, | ||
| isRpcHealthy: true, | ||
| }, | ||
| }} | ||
| > | ||
| <AuthEntries invocations={[authorizedInvocation]} /> | ||
| </Wrapper>, | ||
| ); | ||
| await waitFor(() => screen.getAllByTestId("AuthEntryContainer")); | ||
| await fireEvent.click(screen.getByTestId("AuthEntryBtn")); | ||
| await waitFor(() => screen.getAllByTestId("AuthEntryContent")); | ||
|
|
||
| expect(screen.getByTestId("AuthEntryBtn__Title")).toHaveTextContent( | ||
| "transfer", | ||
| ); | ||
|
|
||
| expect(getContractSpecSpy).not.toHaveBeenCalled(); | ||
|
|
||
| const parameterKeys = screen.getAllByTestId("ParameterKey"); | ||
| const parameterValues = screen.getAllByTestId("ParameterValue"); | ||
|
|
||
| expect(parameterKeys).toHaveLength(3); | ||
| expect(parameterKeys[0]).toHaveTextContent(""); | ||
| expect(parameterKeys[1]).toHaveTextContent(""); | ||
| expect(parameterKeys[2]).toHaveTextContent(""); | ||
|
|
||
| expect(parameterValues).toHaveLength(3); | ||
| expect(parameterValues[0]).toHaveTextContent(TEST_PUBLIC_KEY); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -380,11 +380,13 @@ export const KeyValueInvokeHostFnArgs = ({ | |
| contractId, | ||
| fnName, | ||
| showHeader = true, | ||
| isAuthEntry = false, | ||
| }: { | ||
| args: xdr.ScVal[]; | ||
| contractId?: string; | ||
| fnName?: string; | ||
| showHeader?: boolean; | ||
| isAuthEntry?: boolean; | ||
| }) => { | ||
| const [isLoading, setLoading] = React.useState(true); | ||
| const [argNames, setArgNames] = React.useState([] as string[]); | ||
|
|
@@ -405,12 +407,12 @@ export const KeyValueInvokeHostFnArgs = ({ | |
| } | ||
| } | ||
|
|
||
| if (contractId && fnName) { | ||
| if (contractId && fnName && !isAuthEntry) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't fetch the spec if we're populating the authorization parameters |
||
| getSpec(contractId, fnName); | ||
| } else { | ||
| setLoading(false); | ||
| } | ||
| }, [contractId, fnName, networkDetails]); | ||
| }, [contractId, fnName, networkDetails, isAuthEntry]); | ||
|
|
||
| return isLoading ? ( | ||
| <div className="Operations__pair--invoke" data-testid="OperationKeyVal"> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt about adding coverage for CreateContractArgsV1 as well as the other executable types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup - added in e3c414a
Added the other
SorobanAuthorizedFunctiontypes:sorobanAuthorizedFunctionTypeContractFnandsorobanAuthorizedFunctionTypeCreateContractHostFn