Unit tests fixes ( 1 failing left ).

This commit is contained in:
Adrian Tiberius 2015-06-01 21:31:10 +02:00
parent 46a334e333
commit 99b55f3353
15 changed files with 95 additions and 120 deletions

View File

@ -25,8 +25,6 @@ plugins {
id 'com.jfrog.bintray' version '1.0'
}
apply plugin: 'com.jfrog.artifactory-upload'
sourceCompatibility = 1.7
mainClassName = 'org.ethereum.Start'
@ -39,7 +37,6 @@ configurations {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
mavenCentral()
maven { url 'http://repo.spring.io/plugins-release-local' }
flatDir {
dirs "libs"
@ -56,9 +53,6 @@ antlr4 {
preBuild.dependsOn antlr4
configurations {
compile.extendsFrom antlr4
}
ext {
slf4jVersion = '1.7.7'
@ -108,7 +102,7 @@ dependencies {
compile 'com.yuvalshavit:antlr-denter:1.1'
compile 'org.slf4j:slf4j-android:1.7.12'
compile "org.slf4j:slf4j-log4j12:${slf4jVersion}"
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'com.google.code.findbugs:jsr305:3.0.0'
@ -116,8 +110,11 @@ dependencies {
compile 'org.apache.commons:commons-collections4:4.0'
compile "commons-codec:commons-codec:1.10"
compile 'org.hsqldb:hsqldb:1.8.0.10' // best performance - do not upgrade!
compile ("org.hibernate:hibernate-core:${hibernateVersion}") {
exclude group: 'commons-logging', module: 'commons-logging'
}
compile "org.hibernate:hibernate-entitymanager:${hibernateVersion}"
compile 'javax.persistence:persistence-api:1.0.2'
compile('redis.clients:jedis:2.6.0') {
exclude group: 'org.apache.commons', module: 'commons-pool2'

View File

@ -5,8 +5,6 @@ import org.ethereum.core.Transaction;
import org.ethereum.datasource.KeyValueDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@ -18,9 +16,6 @@ import java.net.URI;
import java.util.Map;
import java.util.Set;
//import static org.springframework.util.StringUtils.isEmpty;
//@Component
public class RedisConnectionImpl implements RedisConnection {
private static final Logger logger = LoggerFactory.getLogger("db");
@ -54,20 +49,16 @@ public class RedisConnectionImpl implements RedisConnection {
private static JedisPool createJedisPool(URI redisUri) {
String userInfo = redisUri.getUserInfo();
if (hasText(userInfo)) {
/*
return new JedisPool(new JedisPoolConfig(),
redisUri.getHost(),
redisUri.getPort(),
Protocol.DEFAULT_TIMEOUT,
userInfo.split(":", 2)[1]);
*/
}
/*
return new JedisPool(new JedisPoolConfig(),
redisUri.getHost(),
redisUri.getPort(),
Protocol.DEFAULT_TIMEOUT);
*/
return null;
}

View File

@ -7,6 +7,7 @@ import org.ethereum.listener.EthereumListener;
import javax.inject.Singleton;
import dagger.Component;
import org.ethereum.net.server.ChannelManager;
@Singleton
@Component(modules = EthereumModule.class)
@ -14,4 +15,5 @@ public interface EthereumComponent {
Ethereum ethereum();
EthereumListener listener();
ChannelManager channelManager();
}

View File

@ -9,15 +9,6 @@ import org.ethereum.db.RepositoryImpl;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.Collections;
import java.util.HashSet;
@ -26,23 +17,16 @@ import java.util.Set;
import static org.ethereum.config.SystemProperties.CONFIG;
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "org.ethereum")
public class CommonConfig {
private static final Logger logger = LoggerFactory.getLogger("general");
@Autowired
private RedisConnection redisConnection;
@Bean
Repository repository() {
return new RepositoryImpl(keyValueDataSource(), keyValueDataSource());
}
@Bean
@Scope("prototype")
public KeyValueDataSource keyValueDataSource() {
String dataSource = CONFIG.getKeyValueDataSource();
try {
@ -58,7 +42,6 @@ public class CommonConfig {
}
}
@Bean
public Set<Transaction> pendingTransactions() {
String storage = "Redis";
try {
@ -73,7 +56,7 @@ public class CommonConfig {
}
}
@Bean
/*
public SessionFactory sessionFactory() {
LocalSessionFactoryBuilder builder =
new LocalSessionFactoryBuilder(dataSource());
@ -82,6 +65,7 @@ public class CommonConfig {
return builder.buildSessionFactory();
}
*/
private Properties getHibernateProperties() {
@ -96,13 +80,11 @@ public class CommonConfig {
"org.hibernate.dialect.HSQLDialect");
return prop;
}
@Bean
/*
public HibernateTransactionManager txManager() {
return new HibernateTransactionManager(sessionFactory());
}
@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
logger.info("Connecting to the block store");
@ -123,5 +105,5 @@ public class CommonConfig {
return ds;
}
*/
}

View File

@ -3,26 +3,14 @@ package org.ethereum.facade;
import org.ethereum.db.BlockStore;
import org.ethereum.db.BlockStoreImpl;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author: Roman Mandeleil
* Created on: 27/01/2015 01:05
*/
@Configuration
@Import(CommonConfig.class)
public class DefaultConfig {
@Autowired CommonConfig commonConfig;
@Bean
@Transactional(propagation = Propagation.SUPPORTS)
public BlockStore blockStore(SessionFactory sessionFactory){
return new BlockStoreImpl(sessionFactory);
}

View File

@ -6,19 +6,14 @@ import org.ethereum.net.shh.ShhHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
/**
* @author Roman Mandeleil
* @since 13.11.2014
*/
@Component
public class EthereumFactory {
private static final Logger logger = LoggerFactory.getLogger("general");
public static ApplicationContext context = null;
public static Ethereum createEthereum() {
return createEthereum(DefaultConfig.class);
@ -29,8 +24,7 @@ public class EthereumFactory {
logger.info("capability eth version: [{}]", EthHandler.VERSION);
logger.info("capability shh version: [{}]", ShhHandler.VERSION);
context = new AnnotationConfigApplicationContext(clazz);
return context.getBean(Ethereum.class);
return null;
}
}

View File

@ -3,29 +3,15 @@ package org.ethereum.facade;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author: Roman Mandeleil
* Created on: 27/01/2015 01:05
*/
@Configuration
@Import(CommonConfig.class)
public class RemoteConfig {
@Autowired CommonConfig commonConfig;
// todo: init total difficulty
// todo: init last 1000 blocks
@Bean
@Transactional(propagation = Propagation.SUPPORTS)
public BlockStore blockStore(SessionFactory sessionFactory){
return new InMemoryBlockStore();
}

View File

@ -6,6 +6,9 @@ import org.ethereum.core.BlockchainImpl;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.core.Wallet;
import org.ethereum.db.*;
import org.ethereum.di.components.DaggerEthereumComponent;
import org.ethereum.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.Repository;
import org.ethereum.jsontestsuite.builder.BlockBuilder;
import org.ethereum.jsontestsuite.builder.RepositoryBuilder;
@ -47,6 +50,10 @@ public class TestRunner {
@Inject
public TestRunner() {
channelManager = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule())
.build().channelManager();
}
public List<String> runTestSuite(TestSuite testSuite) {

View File

@ -5,10 +5,6 @@ import org.ethereum.facade.Ethereum;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import java.sql.SQLException;
import java.util.Properties;
@ -19,6 +15,7 @@ import java.util.Properties;
*/
public class TestContext {
/*
private static final Logger logger = LoggerFactory.getLogger("test");
@ -56,11 +53,11 @@ public class TestContext {
}
/*
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
*/
// <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
// <property name="entityManagerFactory" ref="entityManagerFactory" />
// </bean>
@Bean(name = "dataSource")
@ -88,5 +85,5 @@ public class TestContext {
@Autowired
Ethereum eth;
*/
}

View File

@ -4,23 +4,18 @@ package org.ethereum.core;
import org.ethereum.config.SystemProperties;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
import org.ethereum.di.modules.TestEthereumModule;
import org.ethereum.di.components.DaggerTestEthereumComponent;
import org.ethereum.facade.Ethereum;
import org.ethereum.manager.WorldManager;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.ethereum.TestContext;
import java.io.File;
@ -31,32 +26,40 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import javax.inject.Inject;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public class ImportTest {
private static final Logger logger = LoggerFactory.getLogger("test");
@Configuration
@ComponentScan(basePackages = "org.ethereum")
static class ContextConfiguration extends TestContext {
static {
SystemProperties.CONFIG.setDataBaseDir("test_db/" + ImportTest.class);
SystemProperties.CONFIG.setDatabaseReset(true);
}
@Bean
@Transactional(propagation = Propagation.SUPPORTS)
public BlockStore blockStore(SessionFactory sessionFactory){
return new InMemoryBlockStore();
}
}
@Autowired
@Inject
WorldManager worldManager;
@Inject
public ImportTest() {
}
@Before
public void setup() {
worldManager = DaggerTestEthereumComponent.builder()
.testEthereumModule(new TestEthereumModule())
.build().worldManager();
}
@After
public void close(){
worldManager.close();

View File

@ -4,51 +4,53 @@ import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.redis.RedisConnection;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
import org.ethereum.di.components.TestEthereumComponent;
import org.ethereum.di.components.DaggerTestEthereumComponent;
import org.ethereum.di.modules.TestEthereumModule;
import org.ethereum.manager.WorldManager;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.Jedis;
import org.ethereum.TestContext;
import java.net.URI;
import javax.inject.Inject;
import static org.junit.Assert.assertFalse;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public abstract class AbstractRedisTest {
@Configuration
@ComponentScan(basePackages = "org.ethereum")
static class ContextConfiguration extends TestContext {
static {
SystemProperties.CONFIG.setDataBaseDir("test_db/" + "RedisAll");
SystemProperties.CONFIG.setDatabaseReset(true);
}
@Bean
@Transactional(propagation = Propagation.SUPPORTS)
public BlockStore blockStore(SessionFactory sessionFactory){
return new InMemoryBlockStore();
}
}
@Autowired
private RedisConnection redisConnection;
TestEthereumComponent component;
@Autowired
@Inject
RedisConnection redisConnection;
@Inject
WorldManager worldManager;
@Before
public void setup() {
component = DaggerTestEthereumComponent.builder()
.testEthereumModule(new TestEthereumModule())
.build();
redisConnection = component.redisConnection();
worldManager = component.worldManager();
}
@After
public void close(){
worldManager.close();

View File

@ -1,6 +1,7 @@
package org.ethereum.di.components;
import org.ethereum.di.modules.EthereumModule;
import org.ethereum.datasource.redis.RedisConnection;
import org.ethereum.di.modules.TestEthereumModule;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.WorldManager;
@ -11,7 +12,7 @@ import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = EthereumModule.class)
@Component(modules = TestEthereumModule.class)
public interface TestEthereumComponent {
void inject(ChannelManager channelManager);
@ -21,4 +22,5 @@ public interface TestEthereumComponent {
EthereumListener listener();
ChannelManager channelManager();
WorldManager worldManager();
RedisConnection redisConnection();
}

View File

@ -4,6 +4,8 @@ import org.ethereum.config.SystemProperties;
import org.ethereum.core.BlockchainImpl;
import org.ethereum.core.Wallet;
import org.ethereum.datasource.LevelDbDataSource;
import org.ethereum.datasource.redis.RedisConnection;
import org.ethereum.datasource.redis.RedisConnectionImpl;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
import org.ethereum.db.RepositoryImpl;
@ -115,6 +117,13 @@ public class TestEthereumModule {
return new ProgramInvokeFactoryImpl();
}
@Provides
@Singleton
RedisConnection provideRedisConnection() {
return new RedisConnectionImpl();
}
@Provides
EthHandler provideEthHandler(Blockchain blockchain, EthereumListener listener, Wallet wallet) {
return new EthHandler(blockchain, listener, wallet);
@ -151,6 +160,8 @@ public class TestEthereumModule {
return new WorkerThread(discoveryChannelProvider);
}
@Provides
String provideRemoteId() {
return SystemProperties.CONFIG.activePeerNodeid();

View File

@ -1,6 +1,10 @@
package org.ethereum.jsontestsuite;
import org.ethereum.di.modules.TestEthereumModule;
import org.ethereum.di.components.DaggerTestEthereumComponent;
import org.ethereum.facade.Ethereum;
import org.json.simple.parser.ParseException;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
@ -16,6 +20,13 @@ public class GitHubBlockTest {
//SHACOMMIT of tested commit, ethereum/tests.git
public String shacommit = "d2ba02fe0507da205e3d17d79612ae15282b35a2";
@Before
public void setup() {
DaggerTestEthereumComponent.builder()
.testEthereumModule(new TestEthereumModule())
.build();
}
@Ignore
@Test
public void runSingleTest() throws ParseException, IOException {

View File

@ -1,10 +1,12 @@
package org.ethereum.net.wire;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.net.client.Capability;
import org.ethereum.net.eth.EthHandler;
import org.ethereum.net.eth.EthMessageCodes;
import org.ethereum.net.p2p.P2pHandler;
import org.ethereum.net.p2p.P2pMessageCodes;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.shh.ShhHandler;
import org.ethereum.net.shh.ShhMessageCodes;
@ -97,7 +99,7 @@ public class AdaptiveMessageIdsTest {
@Test
public void test4() {
P2pHandler p2pHandler = new P2pHandler();
P2pHandler p2pHandler = new P2pHandler(new PeerDiscovery(), new CompositeEthereumListener());
List<Capability> capabilities = Arrays.asList(
new Capability(Capability.ETH, EthHandler.VERSION),
@ -124,7 +126,7 @@ public class AdaptiveMessageIdsTest {
@Test // Capabilities should be read in alphabetical order
public void test5() {
P2pHandler p2pHandler = new P2pHandler();
P2pHandler p2pHandler = new P2pHandler(new PeerDiscovery(), new CompositeEthereumListener());
List<Capability> capabilities = Arrays.asList(
new Capability(Capability.SHH, ShhHandler.VERSION),