Skip to content

Commit

Permalink
Merge pull request #225 from Holt666/develop
Browse files Browse the repository at this point in the history
system-lambda upgrade
  • Loading branch information
LucasMLK committed May 14, 2023
2 parents dc31f4a + 90bc015 commit 49a8369
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 52 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<jline.version>3.23.0</jline.version>
<junit.version>4.13.2</junit.version>
<mockito.version>5.2.0</mockito.version>
<system-rules.version>1.19.0</system-rules.version>
<system-lambda.version>1.2.1</system-lambda.version>
<log4j.version>2.20.0</log4j.version>
<surefire.test.excludes>**/*RandomXSyncTest.java,**/*SyncTest.java,**/*SnapshotJTest.java</surefire.test.excludes>
</properties>
Expand Down Expand Up @@ -579,8 +579,8 @@

<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>${system-rules.version}</version>
<artifactId>system-lambda</artifactId>
<version>${system-lambda.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
50 changes: 22 additions & 28 deletions src/test/java/io/xdag/cli/XdagCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

package io.xdag.cli;

import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
import static io.xdag.utils.WalletUtils.WALLET_PASSWORD_PROMPT;
import static java.lang.System.setErr;
import static java.lang.System.setOut;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -48,40 +52,25 @@
import io.xdag.utils.BytesUtils;
import io.xdag.Wallet;

import java.security.Security;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.mockito.Mockito;

import com.google.common.collect.Lists;

public class XdagCliTest {

static { Security.addProvider(new BouncyCastleProvider()); }

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
@Rule
public final SystemOutRule outRule = new SystemOutRule();
@Rule
public final SystemErrRule errRule = new SystemErrRule();
private Config config;

@Before
public void setUp() throws Exception {
config = new DevnetConfig();
outRule.mute();
errRule.mute();
}

@Test
Expand All @@ -94,10 +83,11 @@ public void testMain() throws Exception {

@Test
public void testHelp() throws Exception {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
setOut(new PrintStream(captureOutputStream));
XdagCli xdagCLI = spy(new XdagCli());
xdagCLI.start(new String[]{"--help"});
outRule.enableLog();
xdagCLI.printHelp();

String helpStr = """
usage: ./xdag.sh [options]
--account <action> init|create|list
Expand All @@ -112,16 +102,16 @@ public void testHelp() throws Exception {
--password <password> wallet password
--version show version
""";
assertEquals(helpStr, outRule.getLog());
assertEquals(helpStr, tapSystemOut(xdagCLI::printHelp));
}

@Test
public void testVersion() throws Exception {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
setOut(new PrintStream(captureOutputStream));
XdagCli xdagCLI = spy(new XdagCli());
xdagCLI.start(new String[]{"--version"});
outRule.enableLog();
xdagCLI.printVersion();
assertEquals(Constants.CLIENT_VERSION + "\n", outRule.getLog());
assertEquals(Constants.CLIENT_VERSION + "\n", tapSystemOut(xdagCLI::printVersion));
}

@Test
Expand Down Expand Up @@ -258,6 +248,8 @@ public void testStartKernelWithEmptyWallet() throws Exception {

@Test
public void testStartKernelWithEmptyWalletInvalidNewPassword() throws Exception {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
setErr(new PrintStream(captureOutputStream));
XdagCli xdagCLI = spy(new XdagCli());
xdagCLI.setConfig(config);
// mock wallet
Expand All @@ -271,12 +263,8 @@ public void testStartKernelWithEmptyWalletInvalidNewPassword() throws Exception
// mock password
doReturn("a").doReturn("b").when(xdagCLI).readPassword(any());

// mock exits
doNothing().when(xdagCLI).exit(anyInt());

exit.expectSystemExitWithStatus(-1);
// execution
xdagCLI.start();
assertEquals(-1, catchSystemExit(xdagCLI::start));
}

@Test
Expand Down Expand Up @@ -308,6 +296,8 @@ public void testAccountList() throws Exception {

@Test
public void testCreateAccount() throws Exception {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
setOut(new PrintStream(captureOutputStream));
XdagCli xdagCLI = spy(new XdagCli());
xdagCLI.setConfig(config);
// mock wallet
Expand Down Expand Up @@ -364,6 +354,8 @@ public void testListAccounts() throws Exception {

@Test
public void testChangePasswordIncorrectConfirmation() {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
setErr(new PrintStream(captureOutputStream));
XdagCli xdagCLI = spy(new XdagCli());
xdagCLI.setConfig(config);

Expand Down Expand Up @@ -487,6 +479,8 @@ public void testImportPrivateKeyFailedToFlushWalletFile() throws Exception {

@Test
public void testImportPrivateKey() throws Exception {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
setOut(new PrintStream(captureOutputStream));
XdagCli xdagCLI = spy(new XdagCli());
xdagCLI.setConfig(config);

Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/xdag/consensus/SyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@
import io.xdag.utils.XdagTime;
import io.xdag.Wallet;
import java.math.BigInteger;
import java.security.Security;
import java.util.Collections;
import java.util.List;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.MutableBytes32;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPPrivateKey;
import org.junit.Before;
Expand All @@ -70,8 +68,6 @@

public class SyncTest {

static { Security.addProvider(new BouncyCastleProvider()); }

@Rule
public TemporaryFolder root1 = new TemporaryFolder();
@Rule
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/xdag/core/BlockchainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@
import io.xdag.Wallet;
import java.io.IOException;
import java.math.BigInteger;
import java.security.Security;
import java.util.Collections;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.tuweni.bytes.Bytes32;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPPrivateKey;
import org.junit.After;
Expand All @@ -85,8 +83,6 @@
@Slf4j
public class BlockchainTest {

static { Security.addProvider(new BouncyCastleProvider()); }

@Rule
public TemporaryFolder root = new TemporaryFolder();

Expand Down
6 changes: 1 addition & 5 deletions src/test/java/io/xdag/crypto/Bip32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,19 @@

import io.xdag.utils.Numeric;
import java.nio.ByteBuffer;
import java.security.Security;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.io.Base58;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Test;

/**
* BIP-32 implementation test.
*
* <p>Test vectors taken from BIP-32 definition
* https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
* <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">bip32</a>
*/
public class Bip32Test {

static { Security.addProvider(new BouncyCastleProvider()); }

public static Bytes addChecksum(byte[] input) {
int inputLength = input.length;
byte[] checksummed = new byte[inputLength + 4];
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/xdag/crypto/Libp2pCryptoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@
import io.libp2p.core.crypto.PubKey;
import io.libp2p.crypto.keys.Secp256k1Kt;
import io.xdag.utils.Numeric;
import java.security.Security;
import org.apache.tuweni.bytes.Bytes;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Before;
import org.junit.Test;

public class Libp2pCryptoTest {

static { Security.addProvider(new BouncyCastleProvider()); }

private PrivKey libp2pPrivKey;
private PubKey libp2pPubKey;

Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/xdag/wallet/WalletUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
import io.xdag.utils.WalletUtils;

import java.io.IOException;
import java.security.Security;
import java.util.Collections;
import org.apache.tuweni.io.Base58;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
import org.junit.After;
import org.junit.Before;
Expand All @@ -54,8 +52,6 @@

public class WalletUtilsTest {

static { Security.addProvider(new BouncyCastleProvider()); }

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private String pwd;
Expand Down

0 comments on commit 49a8369

Please sign in to comment.