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

Fix the unit tests for the nested map call #423

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

Lbqds
Copy link
Member

@Lbqds Lbqds commented Sep 11, 2024

We still need to keep the initialMaps in the TestContractParams because we cannot put the contract state that needs to be tested into existingContracts.

@Lbqds Lbqds requested review from polarker and h0ngcha0 September 11, 2024 08:59
Copy link
Member

@polarker polarker left a comment

Choose a reason for hiding this comment

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

Great work 👍 A few minor remarks

@@ -942,7 +949,7 @@ export interface TestContractParams<
initialMaps?: M
initialAsset?: Asset // default 1 ALPH
testArgs: A
existingContracts?: ContractState[] // default no existing contracts
existingContracts?: (ContractState | ContractStateWithMaps)[] // default no existing contracts
Copy link
Member

Choose a reason for hiding this comment

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

Since ContractStateWithMaps extends ContractState, we could just use ContractStateWithMaps?

testArgs: params.testArgs === undefined ? {} : params.testArgs,
existingContracts: (params.existingContracts ?? []).concat(contractStates)
existingContracts: Array.prototype.concat(existingContracts, selfMapEntries, existingMapEntries)
Copy link
Member

Choose a reason for hiding this comment

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

It seems it's recommended to use existingContracts.concat(selfMapEntries, existingMapEntries)

return {
...testResult,
maps
maps: allMaps.find((v) => v.address === selfAddress)?.maps
} as TestContractResult<R, M>
}
Copy link
Member

Choose a reason for hiding this comment

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

This function is a bit bloated. Let's maybe introduce a few utility functions.

@polarker polarker merged commit c3dca20 into master Sep 11, 2024
6 of 7 checks passed
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.

2 participants