Skip to content

Commit

Permalink
problem: Transaction Log JSON contains extra tx hash
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Oct 22, 2024
1 parent 58f97f8 commit 82f4966
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void setInput(HexData input) {
this.input = input;
}

@JsonIgnore
public TransactionSignature getSignature() {
if (signature != null) {
return signature;
Expand All @@ -256,6 +257,7 @@ public TransactionSignature getSignature() {
return created;
}

@JsonIgnore
public void setSignature(TransactionSignature signature) {
this.signature = signature;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package io.emeraldpay.etherjar.rpc.json;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand Down Expand Up @@ -163,6 +164,7 @@ public void setTopics(List<Hex32> topics) {
}

@Override
@JsonIgnore
public TransactionId getHash() {
return transactionHash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package io.emeraldpay.etherjar.rpc.json;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand Down Expand Up @@ -253,6 +254,7 @@ public void setRoot(Hex32 root) {
}

@Override
@JsonIgnore
public TransactionId getHash() {
return transactionHash;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package io.emeraldpay.etherjar.rpc.json

import com.fasterxml.jackson.databind.ObjectMapper
import io.emeraldpay.etherjar.domain.Address
import io.emeraldpay.etherjar.domain.TransactionId
import io.emeraldpay.etherjar.hex.Hex32
import io.emeraldpay.etherjar.hex.HexData
import io.emeraldpay.etherjar.rpc.JacksonRpcConverter
import spock.lang.Specification

class TransactionLogJsonSpec extends Specification {

JacksonRpcConverter jacksonRpcConverter = new JacksonRpcConverter()
ObjectMapper objectMapper = jacksonRpcConverter.getObjectMapper()

def "Equals with topics values"() {
setup:
// val1 and val2 topics are both lists, but different implementations
Expand Down Expand Up @@ -75,4 +83,26 @@ class TransactionLogJsonSpec extends Specification {
equals33
!equals34
}

def "Should not generate extra hash field"() {
setup:

def tx = new TransactionLogJson()
tx.transactionHash = TransactionId.from("0xc765d3a679254d60a519d83f33059f882875ad67d4114fb3de4c87a446fd0e52")
tx.setTopics([
Hex32.from("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
Hex32.from("0x00000000000000000000000009b77fda4f5d9016d2cbe1d9fd12d465df8f96d5"),
Hex32.from("0x000000000000000000000000ef8801eaf234ff82801821ffe2d78d60a0237f97"),
])
tx.data = HexData.from("0x0000000000000000000000000000000000000000000000000000000012113a25")
tx.address = Address.from("0xdAC17F958D2ee523a2206206994597C13D831ec7")

when:
def json = objectMapper.writeValueAsString(tx)

then:
json.contains("\"transactionHash\":")
!json.contains("\"hash\":")
json.findAll("0xc765d3a679254d60a519d83f33059f882875ad67d4114fb3de4c87a446fd0e52").size() == 1
}
}

0 comments on commit 82f4966

Please sign in to comment.