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

test(case): optimize test case #5456

Closed

Conversation

forfreeday
Copy link
Contributor

@forfreeday forfreeday commented Aug 28, 2023

What does this PR do?
add several test cases to cover more code verification scenarios

Why are these changes required?
to improve test case coverage

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

liukai added 2 commits August 28, 2023 16:18
1. add AccountAssetStoreTest
2. add AssetIssueStoreTest
3. add AssetIssueV2StoreTest
4. add ContractStoreTest
@forfreeday forfreeday linked an issue Aug 28, 2023 that may be closed by this pull request
5 tasks
@Before
public void init() {
accountAssetStore.put(ASSET_KEY, Longs.toByteArray(200L));

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to add blank line

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 blank line does not affect the logic.

try {
ownerCapsule.addAssetV2(ByteArray.fromString(String.valueOf(id)), TOTAL_SUPPLY);
} catch (Exception e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be thrown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is possible not to throw this exception

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall it be throw out but not be caught ?

long assetKey2 = createAsset("testToken2");
AccountCapsule accountCapsule = accountStore.get(ownerCapsule.getAddress().toByteArray());

Map<String, Long> allAssets = accountAssetStore.getAllAssets(accountCapsule.getInstance());
Copy link
Contributor

Choose a reason for hiding this comment

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

Assert the assets count in the map?

assetIssueStore.put(assetIssueCapsule.createDbKey(), assetIssueCapsule);
}

private AssetIssueCapsule createAssetIssue(long id, String name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is id param necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

necessary, which is the ID in two different test cases

AssetIssueContractOuterClass.AssetIssueContract.newBuilder()
.setName(ByteString.copyFrom(firstTokenId.getBytes()))
.build());
assetIssueCapsule.setId(String.valueOf(2L));
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this id have conflict with other test cases?


@Test
public void put() {
String firstTokenId = "efg";
Copy link
Contributor

Choose a reason for hiding this comment

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

why use this name "firstTokenId"?

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 has nothing to do with code logic

new ContractCapsule(contract.build()));
}

private SmartContractOuterClass.SmartContract.Builder createContract(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't return a contractCapsule?

1. add DelegatedResourceStoreTest
2. add DelegationStoreTest
3. modify test case method name
@forfreeday forfreeday closed this Aug 31, 2023
@forfreeday forfreeday deleted the feature/optimize_test_case branch August 31, 2023 16:16
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.

Improve code coverage to 70%
2 participants