Skip to content

Commit

Permalink
chore: update rpc request test case
Browse files Browse the repository at this point in the history
  • Loading branch information
duanyytop committed Mar 28, 2019
1 parent 1ee0233 commit b2933e1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package com.cryptape.cita.protocol.core.methods.response;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.cryptape.cita.protocol.ObjectMapperFactory;
import com.cryptape.cita.protocol.core.Response;

public class AppLog extends Response<List<AppLog.LogResult>> {

@Override
@JsonDeserialize(using = LogResultDeserialiser.class)
public void setResult(List<LogResult> result) {
super.setResult(result);
}
Expand Down Expand Up @@ -77,4 +89,36 @@ public int hashCode() {
}
}


public static class LogResultDeserialiser
extends JsonDeserializer<List<LogResult>> {

private ObjectReader objectReader = ObjectMapperFactory.getObjectReader();

@Override
public List<LogResult> deserialize(
JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException {

List<LogResult> logResults = new ArrayList<>();
JsonToken nextToken = jsonParser.nextToken();

if (nextToken == JsonToken.START_OBJECT) {
Iterator<LogObject> logObjectIterator =
objectReader.readValues(jsonParser, LogObject.class);
while (logObjectIterator.hasNext()) {
logResults.add(logObjectIterator.next());
}
} else if (nextToken == JsonToken.VALUE_STRING) {
jsonParser.getValueAsString();

Iterator<Hash> transactionHashIterator =
objectReader.readValues(jsonParser, Hash.class);
while (transactionHashIterator.hasNext()) {
logResults.add(transactionHashIterator.next());
}
}
return logResults;
}
}
}
107 changes: 1 addition & 106 deletions core/src/test/java/com/cryptape/cita/protocol/core/ResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,110 +250,6 @@ public void testEthCall() {
assertThat(appCall.getValue(), is("0x"));
}

@Test
public void testEthBlockTransactionHashes() {
//CHECKSTYLE:OFF
buildResponse(
"{\n"
+ "\"jsonrpc\":\"2.0\",\n"
+ "\"id\":1,\n"
+ "\"result\":{\n"
+ " \"version\":0,"
+ " \"hash\":\"0xda9e8497221e9d18131292f8b459d62e03c882be4666d084c67b8dcebcce91d1\",\n"
+ " \"header\":{\n"
+ " \"timestamp\":1533101297835,\n"
+ " \"prevHash\":\"0x4391078f4c03c028178e8f1a9f25392a634b098d7737601f1679a8b197fafcf9\","
+ " \"number\":\"0x3ff59\","
+ " \"stateRoot\":\"0x60fb67e5ca3868d292ea44e2c28bb16d83d25793ed629b28f4c8d18de8742a72\","
+ " \"transactionsRoot\":\"0x62d54aa5b82a5813c87a3a4d1d2c3a02e6c88f037c8fb2461e5116e7a9dc2149\","
+ " \"receiptsRoot\":\"0x918334ef71e85bed370065d1f2758d1eb3f089f7e5323a78a633de7a5f07f371\","
+ " \"gasUsed\":\"0x132bd\","
+ " \"proof\":"
+ " {\"Bft\":{"
+ " \"proposal\":\"0xe1b9bba13cb64a920c04f3abc2ea0a98d2db4fb65d233df3afc31c5321bb6054\","
+ " \"height\":261976,"
+ " \"round\":0,"
+ " \"commits\":{"
+ " \"0x486bb688c8d29056bd7f87c26733048b0a6abda6\":\"0x0fc60edaff5f00329e088750119e92af8940e9612d1dbf3ce4158e721faaff592ab43f4bc3c24718631aa4140f8412cefb9086416ba2c280fa85ec83b511ed5f00\","
+ " \"0x31042d4f7662cddf8ded5229db3c5e7302875e10\":\"0x68e3701cec53f96e792ecb02eb390dad074eb26b0d5472be8804929e016cc99d647b9c40e30942270f1fed91f3fc14479c47de603a5de99735b3122b5d08e2c601\","
+ " \"0xee01b9ba97671e8a1891e85b206b499f106822a1\":\"0x34272376d15b8e0658efa8cce056f59d5054b5863a9945c5e8e232c65f2d434476833899912a871e58374c08da78e8279dc02c877221f6a880134ed050bae44700\","
+ " \"0x71b028e49c6f41aaa74932d703c707ecca6d732e\":\"0x7ed41b1ccf137a77eade8bbd4e348534dc26c45c7d8a547adc7286746497f6bf3587f886c87e97dbfadd8e2698827c53123a3fbfddb682c887509342ae030dec01\""
+ " }"
+ " }"
+ " },"
+ " \"proposer\":\"0xee01b9ba97671e8a1891e85b206b499f106822a1\""
+ " },"
+ " \"body\":{"
+ " \"transactions\":["
+ " {"
+ " \"hash\":\"0xab64a7be5f38ab8061419472402c52c9a26f5989b26da5eec4d59d7aa68348e1\","
+ " \"content\":\"0x0aad010a2839663864396337633336616632336561656230323032363938333135656163323334653334373039120f65333031643366313762346566393518c0843d20a6ff0f2a44a9059cbb000000000000000000000000bac68e5cb986ead0253e0632da1131a0a96efa1800000000000000000000000000000000000000000000000000000000000003e83220000000000000000000000000000000000000000000000000000000000000000038011241e1e76fe6f033db9527f0714ba81b4af1f26b9d70210acbf3cebcb916c2f4c7ae70c3fe80a2032d748caa0b90b70159263880ea6b230912f5bb5c62b234ed67a401\""
+ " },"
+ " {"
+ " \"hash\":\"0xcd7fc94a452d78b0041abac36de489c19432d3c208e795099ac13a6327bb4bd8\","
+ " \"content\":\"0x0aad010a2839663864396337633336616632336561656230323032363938333135656163323334653334373039120f65316239383236653737326132306518c0843d20a7ff0f2a44a9059cbb000000000000000000000000bac68e5cb986ead0253e0632da1131a0a96efa1800000000000000000000000000000000000000000000000000000000000003e83220000000000000000000000000000000000000000000000000000000000000000038011241d5c91c9e262c57fd79d6979f8b9205d7d49ed8918edaf8eb8b8e3bf5447b7d6745e57ebcb741486064758c0058750569c4e6a759de293563e9fa156172abcc3500\""
+ " }"
+ " ]"
+ " }"
+ " }"
+ "}");


AppBlock.TendermintCommit[] tendermintCommits = {
new AppBlock.TendermintCommit(
"0x486bb688c8d29056bd7f87c26733048b0a6abda6",
"0x0fc60edaff5f00329e088750119e92af8940e9612d1dbf3ce4158e721faaff592ab43f4bc3c24718631aa4140f8412cefb9086416ba2c280fa85ec83b511ed5f00"),
new AppBlock.TendermintCommit(
"0x31042d4f7662cddf8ded5229db3c5e7302875e10",
"0x68e3701cec53f96e792ecb02eb390dad074eb26b0d5472be8804929e016cc99d647b9c40e30942270f1fed91f3fc14479c47de603a5de99735b3122b5d08e2c601"),
new AppBlock.TendermintCommit(
"0xee01b9ba97671e8a1891e85b206b499f106822a1",
"0x34272376d15b8e0658efa8cce056f59d5054b5863a9945c5e8e232c65f2d434476833899912a871e58374c08da78e8279dc02c877221f6a880134ed050bae44700"),
new AppBlock.TendermintCommit(
"0x71b028e49c6f41aaa74932d703c707ecca6d732e",
"0x7ed41b1ccf137a77eade8bbd4e348534dc26c45c7d8a547adc7286746497f6bf3587f886c87e97dbfadd8e2698827c53123a3fbfddb682c887509342ae030dec01"),
};
AppBlock.Tendermint tendermint = new AppBlock.Tendermint(
"0xe1b9bba13cb64a920c04f3abc2ea0a98d2db4fb65d233df3afc31c5321bb6054",
"261976", "0",tendermintCommits);

AppBlock.Header header = new AppBlock.Header(
1533101297835L,
"0x4391078f4c03c028178e8f1a9f25392a634b098d7737601f1679a8b197fafcf9",
"0x3ff59",
"0x60fb67e5ca3868d292ea44e2c28bb16d83d25793ed629b28f4c8d18de8742a72",
"0x62d54aa5b82a5813c87a3a4d1d2c3a02e6c88f037c8fb2461e5116e7a9dc2149",
"0x918334ef71e85bed370065d1f2758d1eb3f089f7e5323a78a633de7a5f07f371",
"0x132bd",
new AppBlock.Proof(tendermint),
"0xee01b9ba97671e8a1891e85b206b499f106822a1"
);

List<AppBlock.TransactionObject> transactionObjects = new ArrayList<>();
AppBlock.TransactionObject txObj1 = new AppBlock.TransactionObject();
txObj1.setHash("0xab64a7be5f38ab8061419472402c52c9a26f5989b26da5eec4d59d7aa68348e1");
txObj1.setContent("0x0aad010a2839663864396337633336616632336561656230323032363938333135656163323334653334373039120f65333031643366313762346566393518c0843d20a6ff0f2a44a9059cbb000000000000000000000000bac68e5cb986ead0253e0632da1131a0a96efa1800000000000000000000000000000000000000000000000000000000000003e83220000000000000000000000000000000000000000000000000000000000000000038011241e1e76fe6f033db9527f0714ba81b4af1f26b9d70210acbf3cebcb916c2f4c7ae70c3fe80a2032d748caa0b90b70159263880ea6b230912f5bb5c62b234ed67a401");

AppBlock.TransactionObject txObj2 = new AppBlock.TransactionObject();
txObj2.setHash("0xcd7fc94a452d78b0041abac36de489c19432d3c208e795099ac13a6327bb4bd8");
txObj2.setContent("0x0aad010a2839663864396337633336616632336561656230323032363938333135656163323334653334373039120f65316239383236653737326132306518c0843d20a7ff0f2a44a9059cbb000000000000000000000000bac68e5cb986ead0253e0632da1131a0a96efa1800000000000000000000000000000000000000000000000000000000000003e83220000000000000000000000000000000000000000000000000000000000000000038011241d5c91c9e262c57fd79d6979f8b9205d7d49ed8918edaf8eb8b8e3bf5447b7d6745e57ebcb741486064758c0058750569c4e6a759de293563e9fa156172abcc3500");

transactionObjects.add(txObj1);
transactionObjects.add(txObj2);
AppBlock.Body body = new AppBlock.Body(transactionObjects);

String version = "0";
String hash = "0xda9e8497221e9d18131292f8b459d62e03c882be4666d084c67b8dcebcce91d1";
AppBlock.Block block = new AppBlock.Block(
version,
hash,
header,
body
);
//CHECKSTYLE:ON
AppBlock appBlock = deserialiseResponse(AppBlock.class);
assertThat(appBlock.getBlock(), equalTo(block));
}

@Ignore //no support for parity
@Test
Expand Down Expand Up @@ -423,8 +319,7 @@ public void testEthBlockFullTransactionsParity() {
assertThat(appBlock.getBlock(), equalTo(block));
}

// Remove once Geth & Parity return the same v value in transactions
@Ignore //no support for geth
@Ignore
@Test
public void testEthBlockFullTransactionsGeth() {
//CHECKSTYLE:OFF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class InterfaceTest {

public static void main(String[] args) throws Exception {

testGetBlockByNumber(BigInteger.valueOf(0));
testGetBlockByNumber(BigInteger.valueOf(1));

testGetBalance();

Expand Down

0 comments on commit b2933e1

Please sign in to comment.