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

Include ownerId in synthetic child createApproveAllowanceForAllNFT txn #6177

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,14 @@ public TransactionBody.Builder createDeleteAllowance(final ApproveWrapper approv
}

public TransactionBody.Builder createApproveAllowanceForAllNFT(
final SetApprovalForAllWrapper setApprovalForAllWrapper) {
@NonNull final SetApprovalForAllWrapper setApprovalForAllWrapper, @NonNull EntityId ownerId) {

final var builder = CryptoApproveAllowanceTransactionBody.newBuilder();

builder.addNftAllowances(NftAllowance.newBuilder()
.setApprovedForAll(BoolValue.of(setApprovalForAllWrapper.approved()))
.setTokenId(setApprovalForAllWrapper.tokenId())
.setOwner(Objects.requireNonNull(ownerId).toGrpcAccountId())
.setSpender(setApprovalForAllWrapper.to())
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.esaulpaugh.headlong.abi.Tuple;
import com.esaulpaugh.headlong.abi.TypeFactory;
import com.hedera.node.app.service.mono.context.SideEffectsTracker;
import com.hedera.node.app.service.mono.state.submerkle.EntityId;
import com.hedera.node.app.service.mono.store.contracts.WorldLedgers;
import com.hedera.node.app.service.mono.store.contracts.precompile.AbiConstants;
import com.hedera.node.app.service.mono.store.contracts.precompile.InfrastructureFactory;
Expand Down Expand Up @@ -88,8 +89,9 @@ public SetApprovalForAllPrecompile(
@Override
public TransactionBody.Builder body(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
final var nestedInput = tokenId == null ? input : input.slice(24);
final var ownerId = EntityId.fromAddress(senderAddress);
setApprovalForAllWrapper = decodeSetApprovalForAll(nestedInput, tokenId, aliasResolver);
transactionBody = syntheticTxnFactory.createApproveAllowanceForAllNFT(setApprovalForAllWrapper);
transactionBody = syntheticTxnFactory.createApproveAllowanceForAllNFT(setApprovalForAllWrapper, ownerId);
return transactionBody;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ void ercSetApprovalForAll() {
given(feeCalculator.computeFee(any(), any(), any(), any())).willReturn(mockFeeObject);
given(mockFeeObject.serviceFee()).willReturn(1L);

given(syntheticTxnFactory.createApproveAllowanceForAllNFT(SET_APPROVAL_FOR_ALL_WRAPPER))
given(syntheticTxnFactory.createApproveAllowanceForAllNFT(SET_APPROVAL_FOR_ALL_WRAPPER, new EntityId(0, 0, 7L)))
.willReturn(mockSynthBodyBuilder);
given(mockSynthBodyBuilder.build())
.willReturn(TransactionBody.newBuilder().build());
Expand Down Expand Up @@ -1036,7 +1036,7 @@ void hapiSetApprovalForAll() {
given(feeCalculator.computeFee(any(), any(), any(), any())).willReturn(mockFeeObject);
given(mockFeeObject.serviceFee()).willReturn(1L);

given(syntheticTxnFactory.createApproveAllowanceForAllNFT(SET_APPROVAL_FOR_ALL_WRAPPER))
given(syntheticTxnFactory.createApproveAllowanceForAllNFT(SET_APPROVAL_FOR_ALL_WRAPPER, new EntityId(0, 0, 7L)))
.willReturn(mockSynthBodyBuilder);
given(mockSynthBodyBuilder.build())
.willReturn(TransactionBody.newBuilder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.hedera.node.app.service.mono.store.contracts.precompile.HTSTestsUtil.payer;
import static com.hedera.node.app.service.mono.store.contracts.precompile.HTSTestsUtil.receiver;
import static com.hedera.node.app.service.mono.store.contracts.precompile.HTSTestsUtil.royaltyFee;
import static com.hedera.node.app.service.mono.store.contracts.precompile.HTSTestsUtil.sender;
import static com.hedera.node.app.service.mono.store.contracts.precompile.HTSTestsUtil.senderId;
import static com.hedera.node.app.service.mono.store.contracts.precompile.HTSTestsUtil.token;
import static com.hedera.node.app.service.mono.store.contracts.precompile.SyntheticTxnFactory.MOCK_INITCODE;
Expand Down Expand Up @@ -738,12 +739,14 @@ void createsExpectedNonfungibleApproveAllowanceWithoutOwner() {
void createsAdjustAllowanceForAllNFT() {
final var allowances = new SetApprovalForAllWrapper(nonFungible, receiver, true);

final var result = subject.createApproveAllowanceForAllNFT(allowances);
final var result = subject.createApproveAllowanceForAllNFT(allowances, senderId);
final var txnBody = result.build();

assertEquals(
receiver,
txnBody.getCryptoApproveAllowance().getNftAllowances(0).getSpender());
assertEquals(
sender, txnBody.getCryptoApproveAllowance().getNftAllowances(0).getOwner());
assertEquals(
nonFungible,
txnBody.getCryptoApproveAllowance().getNftAllowances(0).getTokenId());
Expand Down
Loading