-
Notifications
You must be signed in to change notification settings - Fork 10
feat: deterministic resource population #443
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
+200
−16
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c7b63e8
feat: deterministic resource population
joe-p 7b3179c
test: add test to ensure resource population is deterministic
joe-p 13116bc
docs: generate latest docs
joe-p d52401c
test: fix comparison string
joe-p 0148c4b
test: fix asset comparison string
joe-p 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
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ import { AlgoAmount } from '../types/amount' | |
import { AppClient } from '../types/app-client' | ||
import { PaymentParams, TransactionComposer } from '../types/composer' | ||
import { Arc2TransactionNote } from '../types/transaction' | ||
import { getABIReturnValue, waitForConfirmation } from './transaction' | ||
import { getABIReturnValue, populateAppCallResources, waitForConfirmation } from './transaction' | ||
|
||
describe('transaction', () => { | ||
const localnet = algorandFixture() | ||
|
@@ -1138,6 +1138,88 @@ describe('Resource population: meta', () => { | |
expect(boxRef).toBeDefined() | ||
expect(boxRef?.appIndex).toBe(0n) | ||
}) | ||
|
||
test('order is deterministic', async () => { | ||
const { algorand, context } = fixture | ||
|
||
const testAccount = context.testAccount | ||
|
||
const v9AppFactory = algorand.client.getAppFactory({ | ||
appSpec: JSON.stringify(v9ARC32), | ||
defaultSender: testAccount, | ||
}) | ||
|
||
const v9AppClient = (await v9AppFactory.send.create({ method: 'createApplication' })).appClient | ||
|
||
await v9AppClient.fundAppAccount({ amount: (118_000).microAlgo() }) | ||
|
||
const accounts = [] | ||
for (let i = 0; i < 4; i++) { | ||
accounts.push(algorand.account.random().addr) | ||
} | ||
|
||
const apps = [] | ||
for (let i = 0; i < 4; i++) { | ||
const app = await v9AppFactory.send.create({ method: 'createApplication' }) | ||
apps.push(app.appClient.appId) | ||
} | ||
|
||
const assets = [] | ||
for (let i = 0; i < 4; i++) { | ||
const res = await algorand.send.assetCreate({ sender: testAccount, total: 1n }) | ||
assets.push(res.assetId) | ||
} | ||
|
||
const appCall = await v9AppClient.params.call({ | ||
method: 'manyResources', | ||
args: [accounts, assets, apps, [1, 2, 3, 4]], | ||
}) | ||
|
||
const composer = algorand.newGroup() | ||
|
||
composer.addAppCallMethodCall(appCall) | ||
|
||
for (let i = 0; i < 10; i++) { | ||
composer.addAppCallMethodCall(await v9AppClient.params.call({ method: 'dummy', note: `${i}` })) | ||
} | ||
|
||
const atc = (await composer.build()).atc | ||
const getResources = async () => { | ||
const populatedAtc = await populateAppCallResources(atc, algorand.client.algod) | ||
|
||
const resources = [] | ||
for (const txnWithSigner of populatedAtc.buildGroup()) { | ||
const txn = txnWithSigner.txn | ||
|
||
for (const acct of txn.applicationCall?.accounts ?? []) { | ||
resources.push(acct.toString()) | ||
} | ||
|
||
for (const asset of txn.applicationCall?.foreignAssets ?? []) { | ||
resources.push(asset.toString()) | ||
} | ||
|
||
for (const app of txn.applicationCall?.foreignApps ?? []) { | ||
resources.push(app.toString()) | ||
} | ||
|
||
for (const box of txn.applicationCall?.boxes ?? []) { | ||
resources.push(`${box.appIndex}-${box.name.toString()}`) | ||
} | ||
} | ||
|
||
return resources | ||
} | ||
|
||
const allResources = [] | ||
for (let i = 0; i < 100; i++) { | ||
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. 100 iterations takes ~800ms on my machine. I think it's good enough to feel confident that it is indeed deterministic |
||
allResources.push(await getResources()) | ||
} | ||
|
||
for (let i = 1; i < allResources.length; i++) { | ||
expect(allResources[i]).toEqual(allResources[0]) | ||
} | ||
}) | ||
}) | ||
|
||
describe('abi return', () => { | ||
|
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
2 changes: 1 addition & 1 deletion
2
tests/example-contracts/resource-packer/artifacts/ExternalApp.arc32.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.
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.
Do we want/need to test the ResourcePackerv8?
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's not needed because v8 is just txn-specific resources, thus we don't have any decisions to make regarding the order they are populated