NonFeeTransferExtractionStrategyImpl implements NonFeeTransferExtractionStrategy { @Override public Iterable<AccountAmount> extractNonFeeTransfers(TransactionBody body, TransactionRecord transactionRecord) { if (!body.hasCryptoCreateAccount() && !body.hasContractCreateInstance() && !body.hasCryptoTransfer() && !body.hasContractCall()) { return Collections.emptyList(); } AccountID payerAccountId = body.getTransactionID().getAccountID(); if (body.hasCryptoTransfer()) { return body.getCryptoTransfer().getTransfers().getAccountAmountsList(); } else if (body.hasCryptoCreateAccount()) { return extractForCreateEntity(body.getCryptoCreateAccount().getInitialBalance(), payerAccountId, transactionRecord.getReceipt().getAccountID(), transactionRecord); } else if (body.hasContractCreateInstance()) { return extractForCreateEntity(body.getContractCreateInstance().getInitialBalance(), payerAccountId, contractIdToAccountId(transactionRecord.getReceipt().getContractID()), transactionRecord); } else { LinkedList<AccountAmount> result = new LinkedList<>(); var amount = body.getContractCall().getAmount(); var contractAccountId = contractIdToAccountId(body.getContractCall().getContractID()); result.add(AccountAmount.newBuilder().setAccountID(contractAccountId).setAmount(amount).build()); result.add(AccountAmount.newBuilder().setAccountID(payerAccountId).setAmount(0 - amount).build()); return result; } }  @Override Iterable<AccountAmount> extractNonFeeTransfers(TransactionBody body, TransactionRecord transactionRecord);  }
@Test void extractNonFeeTransfersCryptoTransfer() { var transactionBody = getCryptoTransferTransactionBody(); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getSimpleTransactionRecord()); assertAll( () -> assertEquals(3, StreamSupport.stream(result.spliterator(), false).count()) , () -> assertResult(transactionBody.getCryptoTransfer().getTransfers().getAccountAmountsList(), result) ); }
@Test void extractNonFeeTransfersCryptoCreate() { var transactionBody = getCryptoCreateTransactionBody(); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getNewAccountTransactionRecord()); assertAll( () -> assertEquals(2, StreamSupport.stream(result.spliterator(), false).count()) , () -> assertResult(createAccountAmounts( payerAccountNum, 0 - initialBalance, newEntityNum, initialBalance), result) ); }
@Test void extractNonFeeTransfersFailedCryptoCreate() { var transactionBody = getCryptoCreateTransactionBody(); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getFailedTransactionRecord()); assertAll( () -> assertEquals(1, StreamSupport.stream(result.spliterator(), false).count()) , () -> assertResult(createAccountAmounts(payerAccountNum, 0 - initialBalance), result) ); }
@Test void extractNonFeeTransfersContractCreate() { var transactionBody = getContractCreateTransactionBody(); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getNewContractTransactionRecord()); assertAll( () -> assertEquals(2, StreamSupport.stream(result.spliterator(), false).count()) , () -> assertResult(createAccountAmounts(payerAccountNum, 0 - initialBalance, newEntityNum, initialBalance), result) ); }
@Test void extractNonFeeTransfersFailedContractCreate() { var transactionBody = getContractCreateTransactionBody(); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getFailedTransactionRecord()); assertAll( () -> assertEquals(1, StreamSupport.stream(result.spliterator(), false).count()) , () -> assertResult(createAccountAmounts(payerAccountNum, 0 - initialBalance), result) ); }
@Test void extractNonFeeTransfersContractCall() { var amount = 123456L; var contractNum = 8888L; var transactionBody = getContractCallTransactionBody(contractNum, amount); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getSimpleTransactionRecord()); assertAll( () -> assertEquals(2, StreamSupport.stream(result.spliterator(), false).count()) , () -> assertResult(createAccountAmounts(contractNum, amount, payerAccountNum, 0 - amount), result) ); }
@Test void extractNonFeeTransfersFileCreateNone() { var transactionBody = getFileCreateTransactionBody(); var result = extractionStrategy.extractNonFeeTransfers(transactionBody, getNewFileTransactionRecord()); assertAll( () -> assertEquals(0, StreamSupport.stream(result.spliterator(), false).count()) ); }