-
Notifications
You must be signed in to change notification settings - Fork 24
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
[BUG] fixes an incorrect reference to the old create contract class for v2 #1661
Merged
aristidesstaffieri
merged 5 commits into
release/5.25.1
from
bug/auth-entry-create-contract-args-parse-3
Nov 14, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a029eec
fixes an incorrect reference to the old create contract class for v2
aristidesstaffieri dcf8ca5
adds test for create contract v1 in sub invoke
aristidesstaffieri 7ad788b
account for invocations that follow the deployer pattern in create co…
aristidesstaffieri ed02faf
updates tests for sac create constructor args and adds optional compo…
aristidesstaffieri 6de9d54
removes comment in tests
aristidesstaffieri 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 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,61 @@ | ||
import { Address, Keypair, xdr } from "stellar-sdk"; | ||
|
||
import { getInvocationArgs } from "../soroban"; | ||
import { TEST_PUBLIC_KEY } from "popup/__testHelpers__"; | ||
|
||
describe("getInvocationArgs", () => { | ||
it("can render a create contract v1", () => { | ||
const assetCode = "KHL"; | ||
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: [], | ||
}); | ||
const invocationArgs = getInvocationArgs(authorizedInvocation); | ||
expect(invocationArgs).toEqual({ | ||
type: "sac", | ||
asset: `${assetCode}:${TEST_PUBLIC_KEY}`, | ||
}); | ||
}); | ||
it("can render a create contract v2", () => { | ||
const assetCode = "KHL"; | ||
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: [], | ||
}); | ||
const invocationArgs = getInvocationArgs(authorizedInvocation); | ||
expect(invocationArgs).toEqual({ | ||
type: "sac", | ||
asset: `${assetCode}:${TEST_PUBLIC_KEY}`, | ||
args: args.constructorArgs(), | ||
}); | ||
}); | ||
}); |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -351,10 +351,12 @@ const AuthDetail = ({ | |
async function getIsToken() { | ||
try { | ||
const transfers = []; | ||
const isToken = await getIsTokenSpec({ | ||
contractId: rootJson.args.source, | ||
networkDetails, | ||
}); | ||
const isToken = !rootJson.args.source | ||
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. for both the invocation and sub invocation this should account for not having a source in the root args. |
||
? false | ||
: await getIsTokenSpec({ | ||
contractId: rootJson.args.source, | ||
networkDetails, | ||
}); | ||
if (isToken && rootJson.args.function === "transfer") { | ||
transfers.push({ | ||
contractId: rootJson.args.source as string, | ||
|
@@ -366,10 +368,12 @@ const AuthDetail = ({ | |
// check for sub transfers | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const subInvocation of rootJson.invocations) { | ||
const isSubInvokeToken = await getIsTokenSpec({ | ||
contractId: subInvocation.args.source, | ||
networkDetails, | ||
}); | ||
const isSubInvokeToken = !subInvocation.args.source | ||
? false | ||
: await getIsTokenSpec({ | ||
contractId: subInvocation.args.source, | ||
networkDetails, | ||
}); | ||
if (isSubInvokeToken && subInvocation.args.function === "transfer") { | ||
transfers.push({ | ||
contractId: subInvocation.args.source as string, | ||
|
@@ -381,6 +385,7 @@ const AuthDetail = ({ | |
} | ||
setAuthTransfers(transfers); | ||
setCheckingTransfers(false); | ||
setLoading(false); | ||
} catch (error) { | ||
console.error(error); | ||
setCheckingTransfers(false); | ||
|
@@ -391,6 +396,7 @@ const AuthDetail = ({ | |
getIsToken(); | ||
} else { | ||
setCheckingTransfers(false); | ||
setLoading(false); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isInvokeContract, rootJsonDepKey]); | ||
|
@@ -439,6 +445,7 @@ const AuthDetail = ({ | |
_getTokenDetails(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [transfersDepKey]); | ||
|
||
return ( | ||
<div className="AuthDetail" data-testid="AuthDetail"> | ||
{isLoading || isCheckingTransfers ? ( | ||
|
@@ -530,6 +537,7 @@ const AuthDetail = ({ | |
operationKey={t("Asset")} | ||
operationValue={truncateString(detail.asset)} | ||
/> | ||
{detail.args && <KeyValueInvokeHostFnArgs args={detail.args} />} | ||
</div> | ||
</React.Fragment> | ||
))} | ||
|
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.
It wasn't super clear to me through the xdr if this was possible for the SAC case but I think there's no reason to not include this line. If SACs will keep using v1 then this conditional won't ever be hit.