diff --git a/pom.xml b/pom.xml index 481b932773..7eb924b307 100644 --- a/pom.xml +++ b/pom.xml @@ -289,6 +289,52 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.21.0 + + + integration/*.java + + + + + integration-test + + test + + integration-test + + + none + + + integration/*.java + + + + + + + org.jacoco + jacoco-maven-plugin + 0.7.9 + + + + prepare-agent + + + + report + integration-test + + report + + + + diff --git a/src/main/java/com/iota/iri/IRI.java b/src/main/java/com/iota/iri/IRI.java index 69c399137d..f012271fa9 100644 --- a/src/main/java/com/iota/iri/IRI.java +++ b/src/main/java/com/iota/iri/IRI.java @@ -78,7 +78,7 @@ public static void main(final String[] args) throws IOException { log.info("IOTA Node initialised correctly."); } - private static void validateParams(final Configuration configuration, final String[] args) throws IOException { + public static void validateParams(final Configuration configuration, final String[] args) throws IOException { boolean configurationInit = configuration.init(); diff --git a/src/test/java/com/iota/iri/APIIntegrationTests.java b/src/test/java/com/iota/iri/APIIntegrationTests.java deleted file mode 100644 index 6eeeabb38e..0000000000 --- a/src/test/java/com/iota/iri/APIIntegrationTests.java +++ /dev/null @@ -1,350 +0,0 @@ -package com.iota.iri; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.jayway.restassured.RestAssured; -import com.jayway.restassured.config.HttpClientConfig; -import com.jayway.restassured.specification.RequestSpecification; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.Matchers.containsString; - -public class APIIntegrationTests { - - // No result should ever take a minute - private static final int SOCKET_TIMEOUT = 60_000; - - // Expect to connect to any service worldwide in under 100 ms - // and to any online machine local in 1 ms. The 50 ms default value is a suggested compromise. - private static final int CONNECTION_TIMEOUT = 50; - - static { - RestAssured.port = 14265; - } - - /** - * Tests can choose to use this method instead of the no-args given() static method - * if they want to manually specify custom timeouts. - * - * @param socket_timeout The Remote host response time. - * @param connection_timeout Remote host connection time & HttpConnectionManager connection return time. - * @return The RequestSpecification to use for the test. - */ - private static RequestSpecification given(int socket_timeout, int connection_timeout) { - return RestAssured.given().config(RestAssured.config() - .httpClient(HttpClientConfig.httpClientConfig() - .setParam("http.conn-manager.timeout", (long) connection_timeout) - .setParam("http.connection.timeout", connection_timeout) - .setParam("http.socket.timeout", socket_timeout))); - } - - private static RequestSpecification given() { - return given(SOCKET_TIMEOUT, CONNECTION_TIMEOUT); - } - - private static Gson gson() { - return new GsonBuilder().create(); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getNodeInfo"}' - */ - @Test - public void shouldTestGetNodeInfo() { - - final Map request = new HashMap<>(); - request.put("command", "getNodeInfo"); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("appName")). - body(containsString("appVersion")). - body(containsString("duration")). - body(containsString("jreAvailableProcessors")). - body(containsString("jreFreeMemory")). - body(containsString("jreMaxMemory")). - body(containsString("jreTotalMemory")). - body(containsString("jreVersion")). - body(containsString("latestMilestone")). - body(containsString("latestMilestoneIndex")). - body(containsString("jreAvailableProcessors")). - body(containsString("latestSolidSubtangleMilestone")). - body(containsString("latestSolidSubtangleMilestoneIndex")). - body(containsString("neighbors")). - body(containsString("packetsQueueSize")). - body(containsString("time")). - body(containsString("tips")). - body(containsString("transactionsToRequest")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getNeighbors"}' - */ - @Test - public void shouldTestGetNeighbors() { - - final Map request = new HashMap<>(); - request.put("command", "getNeighbors"); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("neighbors")). - body(containsString("address")). - body(containsString("numberOfAllTransactions")). - body(containsString("numberOfInvalidTransactions")). - body(containsString("numberOfNewTransactions")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "addNeighbors", "uris": ["udp://8.8.8.8:14265", "udp://8.8.8.5:14265"]}' - */ - @Test - public void shouldTestAddNeighbors() { - - final Map request = new HashMap<>(); - request.put("command", "addNeighbors"); - request.put("uris", new String[]{"udp://8.8.8.8:14265", "udp://8.8.8.5:14265"}); - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("addedNeighbors")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "removeNeighbors", "uris": ["udp://8.8.8.8:14265", "udp://8.8.8.5:14265"]}' - */ - @Test - public void shouldTestRemoveNeighbors() { - - final Map request = new HashMap<>(); - request.put("command", "removeNeighbors"); - request.put("uris", new String[]{"udp://8.8.8.8:14265", "udp://8.8.8.5:14265"}); - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("removedNeighbors")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getTips"}' - */ - @Test - public void shouldTestGetTips() { - - final Map request = new HashMap<>(); - request.put("command", "getTips"); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("hashes")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "findTransactions", "addresses": ["RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVAZETAIRPTM"]}' - */ - @Test - public void shouldTestFindTransactions() { - - final Map request = new HashMap<>(); - request.put("command", "findTransactions"); - request.put("addresses", new String[]{"RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVAZETAIRPTM"}); - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("hashes")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getTrytes", "hashes": ["OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999"]}' - */ - @Test - public void shouldTestGetTrytes() { - - final Map request = new HashMap<>(); - request.put("command", "getTrytes"); - request.put("hashes", new String[]{"OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999"}); - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - //body(containsString("trytes")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getInclusionStates", "transactions": ["QHBYXQWRAHQJZEIARWSQGZJTAIITOZRMBFICIPAVD9YRJMXFXBDPFDTRAHHHP9YPDUVTNOFWZGFGWMYHEKNAGNJHMW"], "tips": ["ZIJGAJ9AADLRPWNCYNNHUHRRAC9QOUDATEDQUMTNOTABUVRPTSTFQDGZKFYUUIE9ZEBIVCCXXXLKX9999"]}' - */ - @Test - public void shouldTestGetInclusionStates() { - - final Map request = new HashMap<>(); - request.put("command", "getInclusionStates"); - request.put("transactions", new String[]{"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"}); - request.put("tips", new String[]{"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"}); - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - //body(containsString("states")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getBalances", "addresses": ["HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ"], "threshold": 100}' - */ - @Test - public void shouldTestGetBalances() { - - final Map request = new HashMap<>(); - request.put("command", "getBalances"); - request.put("addresses", new String[]{"HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ"}); - request.put("threshold", 100); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("milestone")). - body(containsString("milestoneIndex")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "getTransactionsToApprove", "depth": 27}' - */ - @Test - public void shouldTestGetTransactionsToApprove() { - - final Map request = new HashMap<>(); - request.put("command", "getTransactionsToApprove"); - request.put("depth", 27); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then(). - body(containsString("trunkTransaction")). - body(containsString("branchTransaction")). - body(containsString("duration")). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "broadcastTransactions", "trytes": ["BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ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AUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"]}' - */ - @Test - public void shouldTestBroadcastTransactions() { - - final Map request = new HashMap<>(); - request.put("command", "broadcastTransactions"); - request.put("trytes", new String[]{"BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWRTLFGV9XXMYWEMGQEEEDBTIJ9OJOXFAPFQXCDAXOUDMLVYRMRLUDBETOLRJQAEDDLNVIRQJUBZBO9CCFDHIX9MSQCWYAXJVWHCUPTRSXJDESISQPRKZAFKFRULCGVRSBLVFOPEYLEE99JD9SEBALQINPDAZHFAB9RNBH9AZWIJOTLBZVIEJIAYGMC9AZGNFWGRSWAXTYSXVROVNKCOQQIWGPNQZKHUNODGYADPYLZZZUQRTJRTODOUKAOITNOMWNGHJBBA99QUMBHRENGBHTH9KHUAOXBVIVDVYYZMSEYSJWIOGGXZVRGN999EEGQMCOYVJQRIRROMPCQBLDYIGQO9AMORPYFSSUGACOJXGAQSPDY9YWRRPESNXXBDQ9OZOXVIOMLGTSWAMKMTDRSPGJKGBXQIVNRJRFRYEZ9VJDLHIKPSKMYC9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KBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"}); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then() - .log().all().and(). - statusCode(200); - } - - /** - * curl http://localhost:14265 \ - * -X POST \ - * -H 'Content-Type: application/json' \ - * -d '{"command": "storeTransactions", "trytes": ["BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJ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FUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"]}' - */ - @Test - public void shouldTestStoreTransactions() { - - final Map request = new HashMap<>(); - request.put("command", "storeTransactions"); - request.put("trytes", new String[]{"BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWRTLFGV9XXMYWEMGQEEEDBTIJ9OJOXFAPFQXCDAXOUDMLVYRMRLUDBETOLRJQAEDDLNVIRQJUBZBO9CCFDHIX9MSQCWYAXJVWHCUPTRSXJDESISQPRKZAFKFRULCGVRSBLVFOPEYLEE99JD9SEBALQINPDAZHFAB9RNBH9AZWIJOTLBZVIEJIAYGMC9AZGNFWGRSWAXTYSXVROVNKCOQQIWGPNQZKHUNODGYADPYLZZZUQRTJRTODOUKAOITNOMWNGHJBBA99QUMBHRENGBHTH9KHUAOX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OCDSQGXTQHKHUECGWFUUYS9J9NYQ9U9P9UUP9YMZHWWWCIASCFLCMSKTELZWUGCDE9YOKVOVKTAYPHDF9ZCCQAYPJIJNGSHUIHHCOSSOOBUDOKE9CJZGYSSGNCQJVBEFTZFJ9SQUHOASKRRGBSHWKBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"}); - - given(). - contentType("application/json").header("X-IOTA-API-Version", 1). - body(gson().toJson(request)). - when(). - post("/"). - then().log().all().and(). - statusCode(200); - } -} \ No newline at end of file diff --git a/src/test/java/com/iota/iri/integration/APIIntegrationTests.java b/src/test/java/com/iota/iri/integration/APIIntegrationTests.java new file mode 100644 index 0000000000..71c39337ad --- /dev/null +++ b/src/test/java/com/iota/iri/integration/APIIntegrationTests.java @@ -0,0 +1,422 @@ +package com.iota.iri.integration; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.iota.iri.IRI; +import com.iota.iri.IXI; +import com.iota.iri.Iota; +import com.iota.iri.conf.Configuration; +import com.iota.iri.service.API; +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.config.HttpClientConfig; +import com.jayway.restassured.path.json.JsonPath; +import com.jayway.restassured.response.Response; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.fail; + +public class APIIntegrationTests { + + private static final Boolean spawnNode = true; //can be changed to false to use already deployed node + private static final String portStr = "14266"; + private static final String hostName = "http://localhost"; + + // No result should ever take a minute + private static final int SOCKET_TIMEOUT = 60_000; + + // Expect to connect to any service worldwide in under 100 ms + // and to any online machine local in 1 ms. The 50 ms default value is a suggested compromise. + private static final int CONNECTION_TIMEOUT = 50; + private static ResponseSpecification responseSpec; + // Constants used in tests + private static final String[] URIS = {"udp://8.8.8.8:14266", "udp://8.8.8.5:14266"}; + private static final String[] ADDRESSES = {"RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVA"}; + private static final String[] HASHES = {"OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999"}; + //Trytes of "VHBRBB9EWCPDKYIBEZW9XVX9AOBQKSCKSTMJLGBANQ99PR9HGYNH9AJWTMHJQBDJHZVWHZMXPILS99999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DQC9DXCRCEACDUCEAQBTCCDFDVCXCPCSAJ9KBUCHDTCFDEAVACBUACBQAEAWBPCWCADIDSCEAZBPCGDWCPCEAHDCDCDZCEADDPCFDHDEAXCBDEAHDWCTCEAADCDSCTCFDBDXCNDPCHDXCCDBDEACDUCEAHDWCTCEAYBHDHDCDADPCBDEAPCFDADMDEAIDBDSCTCFDEAHDWCTCEAPCIDGDDDXCRCTCGDEACDUCEAQBTCFDADPCBDEARBXCVCWCEAMBCDADADPCBDSCSAEARBTCEAGDTCFDJDTCSCEAPCGDEAHDWCTCEAWBXCBDXCGDHDTCFDEACDUCEAZBIDQC9DXCRCEAFCCDFDZCGDEAXCBDEAHDWCTCEAMBDCZBEAVCCDJDTCFDBDADTCBDHDSAJ9FCWCTCBDEAFCCDFD9DSCEAFCPCFDEASBEAQCFDCDZCTCEACDIDHDEAXCBDEAVACBVAYAQAEAWBPCWCADIDSCEAZBPCGDWCPCEACDDDDDCDGDTCSCEAHDWCTCEAYBHDHDCDADPCBDEADDPCFDHDXCRCXCDDPCHDXCCDBDEAXCBDEAJDXCTCKDEACDUCEAHDWCTCEAIDBDDDFDTCDDPCFDTCSCBDTCGDGDEACDUCEAHDWCTCEAPCFDADTCSCEAUCCDFDRCTCGDSAEARBTCEAKDPCGDEAZCBDCDKDBDEAPCGDEAPCBDEACDIDHDGDDDCDZCTCBDEAQCIDHDEAPCEAFDTCGDDDTCRCHDTCSCEAUCXCVCIDFDTCEAXCBDEAHDWCTCEAMBCDADADXCHDHDTCTCEACDUCEADCBDXCCDBDEAPCBDSCEAZBFDCDVCFDTCGDGDEAMAMBDCZBNASAEAVBPCHDTCFDEAXCBDEAHDWCTCEAKDPCFDQAEAWBPCWCADIDSCEAZBPCGDWCPCEAGDTCFDJDTCSCSASASA99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999OFFLINE9SPAM9ADDRESS99999999999999999999999999999999999999999999999999999999TYPPI999999999999999999999999999SWTASPAM9DOT9COM9999TYPPI99ZDDIDYD99999999999999999999CKGSVHJSB9ULTHWRTKZBLXQRTZUVLYJDTGUFSIPZDDZWGOLHSUBYVFQDJLJQVID9UYIYZYSNXCKJWHP9WPYVGHICFZRMUWPLH9NNBWGXRXBCOYXCYQHSVGUGJJ9PJBSQLGUHFXAKFYCMLWSEWTDZTQMCJWEXS999999LBYUIRQ9GUXYQSJGYDPKTBZILTCYQIXFFIZECBMECIIXBOVY9SDTYQKGNKBDBLRCOBBQGSJTVGMA9999IOTASPAM9DOT9COM9999TYPPI99CDQASXQKE999999999MMMMMMMMMNZB9999999UME99999999999999"}; + private static final String NULL_HASH = "999999999999999999999999999999999999999999999999999999999999999999999999999999999"; + private static final String[] NULL_HASH_LIST = {NULL_HASH}; + + + private static Iota iota; + private static API api; + private static IXI ixi; + private static Configuration configuration; + private static Logger log = LoggerFactory.getLogger(APIIntegrationTests.class); + + + @BeforeClass + public static void setUp() throws Exception { + if (spawnNode) { + //configure node parameters + log.info("IRI integration tests - initializing node."); + configuration = new Configuration(); + String[] args = {"-p", portStr}; + configuration.put(Configuration.DefaultConfSettings.TESTNET, "true"); + IRI.validateParams(configuration, args); + TemporaryFolder dbFolder = new TemporaryFolder(); + TemporaryFolder logFolder = new TemporaryFolder(); + dbFolder.create(); + logFolder.create(); + configuration.put(Configuration.DefaultConfSettings.DB_PATH.name(), logFolder.getRoot().getAbsolutePath()); + configuration.put(Configuration.DefaultConfSettings.DB_LOG_PATH.name(), logFolder.getRoot().getAbsolutePath()); + configuration.put(Configuration.DefaultConfSettings.MWM, "1"); + + //create node + iota = new Iota(configuration); + ixi = new IXI(iota); + api = new API(iota, ixi); + + //init + try { + iota.init(); + api.init(); + ixi.init(configuration.string(Configuration.DefaultConfSettings.IXI_DIR)); + } catch (final Exception e) { + log.error("Exception during IOTA node initialisation: ", e); + fail("Exception during IOTA node initialisation"); + } + log.info("IOTA Node initialised correctly."); + } + } + + @AfterClass + public static void tearDown() throws Exception { + if (spawnNode) { + try { + ixi.shutdown(); + api.shutDown(); + iota.shutdown(); + } catch (final Exception e) { + log.error("Exception occurred shutting down IOTA node: ", e); + fail("Exception occurred shutting down IOTA node"); + } + } + } + + static { + RestAssured.port = Integer.parseInt(portStr); + RestAssured.baseURI = hostName; + + ResponseSpecBuilder builder = new ResponseSpecBuilder(); + builder.expectStatusCode(200); + builder.expectBody(containsString("duration")); + responseSpec = builder.build(); + } + + /** + * Tests can choose to use this method instead of the no-args given() static method + * if they want to manually specify custom timeouts. + * + * @param socket_timeout The Remote host response time. + * @param connection_timeout Remote host connection time & HttpConnectionManager connection return time. + * @return The RequestSpecification to use for the test. + */ + private static RequestSpecification given(int socket_timeout, int connection_timeout) { + return RestAssured.given().config(RestAssured.config() + .httpClient(HttpClientConfig.httpClientConfig() + .setParam("http.conn-manager.timeout", (long) connection_timeout) + .setParam("http.connection.timeout", connection_timeout) + .setParam("http.socket.timeout", socket_timeout))) + .contentType("application/json").header("X-IOTA-API-Version", 1); + } + + private static RequestSpecification given() { + return given(SOCKET_TIMEOUT, CONNECTION_TIMEOUT); + } + + private static Gson gson() { + return new GsonBuilder().create(); + } + + @Test + public void shouldTestGetNodeInfo() { + + final Map request = new HashMap<>(); + request.put("command", "getNodeInfo"); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("appName")). + body(containsString("appVersion")). + body(containsString("duration")). + body(containsString("jreAvailableProcessors")). + body(containsString("jreFreeMemory")). + body(containsString("jreMaxMemory")). + body(containsString("jreTotalMemory")). + body(containsString("jreVersion")). + body(containsString("latestMilestone")). + body(containsString("latestMilestoneIndex")). + body(containsString("jreAvailableProcessors")). + body(containsString("latestSolidSubtangleMilestone")). + body(containsString("latestSolidSubtangleMilestoneIndex")). + body(containsString("neighbors")). + body(containsString("packetsQueueSize")). + body(containsString("time")). + body(containsString("tips")). + body(containsString("transactionsToRequest")); + } + + @Test + public void shouldTestGetNeighbors() { + + final Map request = new HashMap<>(); + request.put("command", "getNeighbors"); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("neighbors")). + body(containsString("address")). + body(containsString("numberOfAllTransactions")). + body(containsString("numberOfInvalidTransactions")). + body(containsString("numberOfNewTransactions")); + } + + @Test + public void shouldTestAddNeighbors() { + + final Map request = new HashMap<>(); + request.put("command", "addNeighbors"); + request.put("uris", URIS); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("addedNeighbors")); + } + + @Test + public void shouldTestRemoveNeighbors() { + + final Map request = new HashMap<>(); + request.put("command", "removeNeighbors"); + request.put("uris", URIS); + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("removedNeighbors")); + } + + @Test + public void shouldTestGetTips() { + + final Map request = new HashMap<>(); + request.put("command", "getTips"); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("hashes")); + } + + @Test + public void shouldTestFindTransactions() { + + final Map request = new HashMap<>(); + request.put("command", "findTransactions"); + request.put("addresses", ADDRESSES); + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("hashes")); + } + + @Test + public void shouldTestGetTrytes() { + + final Map request = new HashMap<>(); + request.put("command", "getTrytes"); + request.put("hashes", HASHES); + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("trytes")); + } + + //@Test + //empty database returns {"error":"This operations cannot be executed: The subtangle has not been updated yet.","duration":0} + public void shouldTestGetInclusionStates() { + + final Map request = new HashMap<>(); + request.put("command", "getInclusionStates"); + request.put("transactions", NULL_HASH_LIST); + request.put("tips", NULL_HASH_LIST); + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("states")); + } + + //@Test + //FIXME: pending https://github.com/iotaledger/iri/issues/618 + public void shouldTestGetBalances() { + + final Map request = new HashMap<>(); + request.put("command", "getBalances"); + request.put("addresses", ADDRESSES); + request.put("threshold", 100); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("milestone")); + } + + //@Test + //empty database returns {"error":"This operations cannot be executed: The subtangle has not been updated yet.","duration":0} + public void shouldTestGetTransactionsToApprove() { + + final Map request = new HashMap<>(); + request.put("command", "getTransactionsToApprove"); + request.put("depth", 27); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("trunkTransaction")). + body(containsString("branchTransaction")); + } + + @Test + public void shouldTestBroadcastTransactions() { + + final Map request = new HashMap<>(); + request.put("command", "broadcastTransactions"); + request.put("trytes", TRYTES); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + log().all().and(); + } + + @Test + public void shouldTestStoreTransactions() { + + final Map request = new HashMap<>(); + request.put("command", "storeTransactions"); + request.put("trytes", TRYTES); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + log().all().and(); + } + + @Test + public void shouldTestattachToTangle() { + + final Map request = new HashMap<>(); + request.put("command", "attachToTangle"); + request.put("trytes", TRYTES); + request.put("trunkTransaction", NULL_HASH); + request.put("branchTransaction", NULL_HASH); + request.put("minWeightMagnitude", configuration.integer(Configuration.DefaultConfSettings.MWM)); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + spec(responseSpec). + body(containsString("trytes")); + } + + @Test + public void shouldSendTransactionAndFetch() throws InterruptedException { + //do PoW + final Map request = new HashMap<>(); + request.put("command", "attachToTangle"); + request.put("trytes", TRYTES); + request.put("trunkTransaction", NULL_HASH); + request.put("branchTransaction", NULL_HASH); + request.put("minWeightMagnitude", configuration.integer(Configuration.DefaultConfSettings.MWM)); + + Response response = given(). + body(gson().toJson(request)). + when(). + post("/"); + response.getBody(); + JsonPath responseJson = response.jsonPath(); + List trytes = responseJson.getList("trytes"); + + //Store + request.clear(); + request.put("command", "storeTransactions"); + request.put("trytes", trytes); + + given(). + body(gson().toJson(request)). + when(). + post("/"). + then(). + log().all().and().spec(responseSpec); + + //Fetch + String temp = (String) trytes.get(0); + String[] addresses = {temp.substring(2187,2268)}; //extract address from trytes + request.clear(); + request.put("command", "findTransactions"); + request.put("addresses", addresses); + response = given(). + body(gson().toJson(request)). + when(). + post("/"); + response.getBody(); + responseJson = response.jsonPath(); + List hashes = responseJson.getList("hashes"); + Assert.assertTrue(!hashes.isEmpty()); + } +} \ No newline at end of file diff --git a/src/test/java/com/iota/iri/NodeIntegrationTests.java b/src/test/java/com/iota/iri/integration/NodeIntegrationTests.java similarity index 98% rename from src/test/java/com/iota/iri/NodeIntegrationTests.java rename to src/test/java/com/iota/iri/integration/NodeIntegrationTests.java index 89db8606dd..3f27ce53a4 100644 --- a/src/test/java/com/iota/iri/NodeIntegrationTests.java +++ b/src/test/java/com/iota/iri/integration/NodeIntegrationTests.java @@ -1,5 +1,7 @@ -package com.iota.iri; +package com.iota.iri.integration; +import com.iota.iri.IXI; +import com.iota.iri.Iota; import com.iota.iri.conf.Configuration; import static com.iota.iri.controllers.TransactionViewModel.*;