-
Notifications
You must be signed in to change notification settings - Fork 30
Add TestKit JUnit extension [ECR-3076] #913
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
13 commits
Select commit
Hold shift + click to select a range
356705b
ECR-3076 Add TestKit extension
MakarovS 60faabd
ECR-3076 Add disposing internal
MakarovS c45e851
Merge remote-tracking branch 'remotes/origin/master' into ECR-3076
MakarovS c5f810d
ECR-3076 Add annotations and review fixes
MakarovS 164948c
ECR-3076 Review fixes and tests
MakarovS 447cbf8
Merge remote-tracking branch 'remotes/origin/master' into ECR-3076
MakarovS b78615b
ECR-3076 Fix tests and review comments
MakarovS 473ca29
Merge remote-tracking branch 'remotes/origin/master' into ECR-3076
MakarovS 9266f6d
ECR-3076 Checkstyle fix
MakarovS 280fd7f
ECR-3076 Use TestKit extension in TestKit tests
MakarovS 2150069
ECR-3076 Review fixes
MakarovS f5baa27
Merge remote-tracking branch 'remotes/origin/master' into ECR-3076
MakarovS 9164ddd
Merge remote-tracking branch 'remotes/origin/master' into ECR-3076
MakarovS 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
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 |
---|---|---|
|
@@ -32,60 +32,65 @@ | |
import com.exonum.binding.storage.indices.ProofMapIndexProxy; | ||
import com.exonum.binding.test.RequiresNativeLibrary; | ||
import com.exonum.binding.testkit.TestKit; | ||
import com.exonum.binding.testkit.TestKitExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
@RequiresNativeLibrary | ||
class TransferTxHistoryTest { | ||
|
||
@RegisterExtension | ||
TestKitExtension testKitExtension = new TestKitExtension( | ||
TestKit.builder() | ||
.withService(CryptocurrencyServiceModule.class)); | ||
|
||
private static final KeyPair ACCOUNT_1 = PredefinedOwnerKeys.FIRST_OWNER_KEY_PAIR; | ||
private static final KeyPair ACCOUNT_2 = PredefinedOwnerKeys.SECOND_OWNER_KEY_PAIR; | ||
|
||
@Test | ||
@RequiresNativeLibrary | ||
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. The same is here. The class and tests are annotated. |
||
void transfersHistoryBetweenTwoAccountsTest() { | ||
try (TestKit testKit = TestKit.forService(CryptocurrencyServiceModule.class)) { | ||
// Create source and target wallets with the same initial balance | ||
long initialBalance = 100L; | ||
TransactionMessage createFromWalletTx1 = | ||
newCreateWalletTransaction(initialBalance, ACCOUNT_1); | ||
TransactionMessage createFromWalletTx2 = | ||
newCreateWalletTransaction(initialBalance, ACCOUNT_2); | ||
testKit.createBlockWithTransactions(createFromWalletTx1, createFromWalletTx2); | ||
void transfersHistoryBetweenTwoAccountsTest(TestKit testKit) { | ||
// Create source and target wallets with the same initial balance | ||
long initialBalance = 100L; | ||
TransactionMessage createFromWalletTx1 = | ||
newCreateWalletTransaction(initialBalance, ACCOUNT_1); | ||
TransactionMessage createFromWalletTx2 = | ||
newCreateWalletTransaction(initialBalance, ACCOUNT_2); | ||
testKit.createBlockWithTransactions(createFromWalletTx1, createFromWalletTx2); | ||
|
||
// Create and execute 1st transaction | ||
long seed1 = 1L; | ||
long transferSum1 = 40L; | ||
TransactionMessage transferTx1 = newTransferTransaction( | ||
seed1, ACCOUNT_1, ACCOUNT_2.getPublicKey(), transferSum1); | ||
testKit.createBlockWithTransactions(transferTx1); | ||
// Create and execute 1st transaction | ||
long seed1 = 1L; | ||
long transferSum1 = 40L; | ||
TransactionMessage transferTx1 = newTransferTransaction( | ||
seed1, ACCOUNT_1, ACCOUNT_2.getPublicKey(), transferSum1); | ||
testKit.createBlockWithTransactions(transferTx1); | ||
|
||
// Create and execute 2nd transaction | ||
long seed2 = 2L; | ||
long transferSum2 = 10L; | ||
TransactionMessage transferTx2 = newTransferTransaction( | ||
seed2, ACCOUNT_2, ACCOUNT_1.getPublicKey(), transferSum2); | ||
testKit.createBlockWithTransactions(transferTx2); | ||
// Create and execute 2nd transaction | ||
long seed2 = 2L; | ||
long transferSum2 = 10L; | ||
TransactionMessage transferTx2 = newTransferTransaction( | ||
seed2, ACCOUNT_2, ACCOUNT_1.getPublicKey(), transferSum2); | ||
testKit.createBlockWithTransactions(transferTx2); | ||
|
||
testKit.withSnapshot((view) -> { | ||
// Check that wallets have correct balances | ||
CryptocurrencySchema schema = new CryptocurrencySchema(view); | ||
ProofMapIndexProxy<PublicKey, Wallet> wallets = schema.wallets(); | ||
long expectedBalance1 = initialBalance - transferSum1 + transferSum2; | ||
assertThat(wallets.get(ACCOUNT_1.getPublicKey()).getBalance()) | ||
.isEqualTo(expectedBalance1); | ||
long expectedBalance2 = initialBalance + transferSum1 - transferSum2; | ||
assertThat(wallets.get(ACCOUNT_2.getPublicKey()).getBalance()) | ||
.isEqualTo(expectedBalance2); | ||
testKit.withSnapshot((view) -> { | ||
// Check that wallets have correct balances | ||
CryptocurrencySchema schema = new CryptocurrencySchema(view); | ||
ProofMapIndexProxy<PublicKey, Wallet> wallets = schema.wallets(); | ||
long expectedBalance1 = initialBalance - transferSum1 + transferSum2; | ||
assertThat(wallets.get(ACCOUNT_1.getPublicKey()).getBalance()) | ||
.isEqualTo(expectedBalance1); | ||
long expectedBalance2 = initialBalance + transferSum1 - transferSum2; | ||
assertThat(wallets.get(ACCOUNT_2.getPublicKey()).getBalance()) | ||
.isEqualTo(expectedBalance2); | ||
|
||
// Check history | ||
HashCode messageHash1 = transferTx1.hash(); | ||
HashCode messageHash2 = transferTx2.hash(); | ||
assertThat(schema.transactionsHistory(ACCOUNT_1.getPublicKey())) | ||
.containsExactly(messageHash1, messageHash2); | ||
assertThat(schema.transactionsHistory(ACCOUNT_2.getPublicKey())) | ||
.containsExactly(messageHash1, messageHash2); | ||
return null; | ||
}); | ||
} | ||
// Check history | ||
HashCode messageHash1 = transferTx1.hash(); | ||
HashCode messageHash2 = transferTx2.hash(); | ||
assertThat(schema.transactionsHistory(ACCOUNT_1.getPublicKey())) | ||
.containsExactly(messageHash1, messageHash2); | ||
assertThat(schema.transactionsHistory(ACCOUNT_2.getPublicKey())) | ||
.containsExactly(messageHash1, messageHash2); | ||
return null; | ||
}); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.