Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated project to latest JUnit 5 and fixed failing test #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/p2p/solanaj/core/AccountKeysListTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.p2p.solanaj.core;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.p2p.solanaj.programs.SystemProgram;

public class AccountKeysListTest {
class AccountKeysListTest {

@Test
public void getSortedList() {
void getSortedList() {
AccountKeysList list = new AccountKeysList();

list.addAll(
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/p2p/solanaj/core/AccountTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.p2p.solanaj.core;

import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;

import org.bitcoinj.core.Base58;
import org.junit.jupiter.api.Test;

public class AccountTest {
class AccountTest {

@Test
public void accountFromSecretKey() {
void accountFromSecretKey() {
byte[] secretKey = Base58
.decode("4Z7cXSyeFR8wNGMVXUE1TwtKn5D5Vu7FzEv69dokLv7KrQk7h6pu4LF8ZRR9yQBhc7uSM6RTTZtU1fmaxiNrxXrs");
assertEquals("QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo", new Account(secretKey).getPublicKey().toString());
Expand All @@ -19,13 +19,13 @@ public void accountFromSecretKey() {
}

@Test
public void generateNewAccount() {
void generateNewAccount() {
Account account = new Account();
assertEquals(64, account.getSecretKey().length);
}

@Test
public void fromMnemonic() {
void fromMnemonic() {
Account acc = Account.fromMnemonic(Arrays.asList("spider", "federal", "bleak", "unable", "ask", "weasel",
"diamond", "electric", "illness", "wheat", "uphold", "mind"), "");

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/p2p/solanaj/core/MainnetTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.p2p.solanaj.core;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.p2p.solanaj.rpc.Cluster;
import org.p2p.solanaj.rpc.RpcClient;
import org.p2p.solanaj.rpc.RpcException;
import org.p2p.solanaj.rpc.types.AccountInfo;

import java.util.List;

import static org.junit.Assert.assertTrue;

public class MainnetTest {
class MainnetTest {

@Test
public void connectToMainnet() {
void connectToMainnet() {

final RpcClient client = new RpcClient(Cluster.MAINNET);
final PublicKey publicKey = new PublicKey("skynetDj29GH6o6bAqoixCpDuYtWqi1rm8ZNx1hB3vq");
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/p2p/solanaj/core/MessageTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.p2p.solanaj.core;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import org.bitcoinj.core.Base58;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.p2p.solanaj.programs.SystemProgram;

import static org.junit.Assert.assertArrayEquals;

public class MessageTest {
class MessageTest {

@Test
public void serializeMessage() {
void serializeMessage() {
PublicKey fromPublicKey = new PublicKey("QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo");
PublicKey toPublickKey = new PublicKey("GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5");
int lamports = 3000;

Account signer = new Account(Base58
PublicKey signer = new PublicKey(Base58
.decode("4Z7cXSyeFR8wNGMVXUE1TwtKn5D5Vu7FzEv69dokLv7KrQk7h6pu4LF8ZRR9yQBhc7uSM6RTTZtU1fmaxiNrxXrs"));

Message message = new Message();
Expand Down
40 changes: 24 additions & 16 deletions src/test/java/org/p2p/solanaj/core/PublicKeyTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package org.p2p.solanaj.core;

import org.junit.Test;
import org.p2p.solanaj.core.PublicKey.ProgramDerivedAddress;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import org.p2p.solanaj.core.PublicKey.ProgramDerivedAddress;

import java.io.ByteArrayOutputStream;
import java.util.Arrays;

public class PublicKeyTest {
class PublicKeyTest {

@Test(expected = IllegalArgumentException.class)
public void ivalidKeys() {
new PublicKey(new byte[] { 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0 });
new PublicKey("300000000000000000000000000000000000000000000000000000000000000000000");
new PublicKey("300000000000000000000000000000000000000000000000000000000000000");
@Test
void ivalidKeys() {
assertThrows(IllegalArgumentException.class, () -> new PublicKey(
new byte[]{3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
0, 0, 0, 0, 0}));
assertThrows(IllegalArgumentException.class, () -> new PublicKey(
"300000000000000000000000000000000000000000000000000000000000000000000"));
assertThrows(IllegalArgumentException.class,
() -> new PublicKey("300000000000000000000000000000000000000000000000000000000000000"));
}

@Test
public void validKeys() {
void validKeys() {
PublicKey key = new PublicKey(new byte[] { 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, });
assertEquals("CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3", key.toString());
Expand All @@ -37,15 +45,15 @@ public void validKeys() {
}

@Test
public void equals() {
void equals() {
PublicKey key = new PublicKey("11111111111111111111111111111111");
assertTrue(key.equals(key));

assertFalse(key.equals(new PublicKey("11111111111111111111111111111112")));
}

@Test
public void readPubkey() {
void readPubkey() {
PublicKey key = new PublicKey("11111111111111111111111111111111");

ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand All @@ -57,7 +65,7 @@ public void readPubkey() {
}

@Test
public void createProgramAddress() throws Exception {
void createProgramAddress() throws Exception {
PublicKey programId = new PublicKey("BPFLoader1111111111111111111111111111111111");

PublicKey programAddress = PublicKey.createProgramAddress(
Expand All @@ -79,7 +87,7 @@ public void createProgramAddress() throws Exception {
}

@Test
public void findProgramAddress() throws Exception {
void findProgramAddress() throws Exception {
PublicKey programId = new PublicKey("BPFLoader1111111111111111111111111111111111");

ProgramDerivedAddress programAddress = PublicKey.findProgramAddress(Arrays.asList("".getBytes()), programId);
Expand All @@ -89,7 +97,7 @@ public void findProgramAddress() throws Exception {
}

@Test
public void findProgramAddress1() throws Exception {
void findProgramAddress1() throws Exception {
PublicKey programId = new PublicKey("6Cust2JhvweKLh4CVo1dt21s2PJ86uNGkziudpkNPaCj");
PublicKey programId2 = new PublicKey("BPFLoader1111111111111111111111111111111111");

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/p2p/solanaj/core/TransactionTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.p2p.solanaj.core;

import org.p2p.solanaj.programs.SystemProgram;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import org.p2p.solanaj.programs.SystemProgram;

import java.util.Base64;

import org.bitcoinj.core.Base58;

public class TransactionTest {
class TransactionTest {

@Test
public void signAndSerialize() {
void signAndSerialize() {
PublicKey fromPublicKey = new PublicKey("QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo");
PublicKey toPublickKey = new PublicKey("GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5");
int lamports = 3000;
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/org/p2p/solanaj/programs/SystemProgramTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.p2p.solanaj.programs;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.p2p.solanaj.core.PublicKey;
import org.p2p.solanaj.core.TransactionInstruction;

import org.junit.Test;
import static org.junit.Assert.*;

import org.bitcoinj.core.Base58;

public class SystemProgramTest {
class SystemProgramTest {

@Test
public void transferInstruction() {
void transferInstruction() {
PublicKey fromPublicKey = new PublicKey("QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo");
PublicKey toPublickKey = new PublicKey("GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5");
int lamports = 3000;
Expand All @@ -26,7 +27,7 @@ public void transferInstruction() {
}

@Test
public void createAccountInstruction() {
void createAccountInstruction() {
TransactionInstruction instruction = SystemProgram.createAccount(SystemProgram.PROGRAM_ID,
SystemProgram.PROGRAM_ID, 2039280, 165, SystemProgram.PROGRAM_ID);

Expand Down
23 changes: 12 additions & 11 deletions src/test/java/org/p2p/solanaj/utils/ByteUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package org.p2p.solanaj.utils;

import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import org.junit.jupiter.api.Test;

public class ByteUtilsTest {
class ByteUtilsTest {

@Test
public void readBytes() {
void readBytes() {
byte[] buf = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

assertArrayEquals(new byte[] { 1, 2, 3, 4 }, ByteUtils.readBytes(buf, 0, 4));
assertArrayEquals(new byte[] { 5, 6, 7, 8, 9, 10, 11, 12 }, ByteUtils.readBytes(buf, 4, 8));
}

@Test
public void readUint64() throws IOException {
void readUint64() throws IOException {
String bigIntValue = "96351551052682965";

ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand All @@ -29,13 +31,12 @@ public void readUint64() throws IOException {
assertEquals(bigIntValue, bn.toString());
}

@Test(expected = RuntimeException.class)
public void uint64ToByteStreamLE() {
@Test
void uint64ToByteStreamLE() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ByteUtils.uint64ToByteStreamLE(new BigInteger("137001898677442802701"), bos);
} catch (IOException e) {
}
assertThrows(RuntimeException.class,
() -> ByteUtils.uint64ToByteStreamLE(new BigInteger("137001898677442802701"), bos));

}

}
9 changes: 5 additions & 4 deletions src/test/java/org/p2p/solanaj/utils/ShortvecEncodingTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.p2p.solanaj.utils;

import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

public class ShortvecEncodingTest {
import org.junit.jupiter.api.Test;

class ShortvecEncodingTest {

@Test
public void encodeLength() {
void encodeLength() {
assertArrayEquals(new byte[] { 0 } /* [0] */, ShortvecEncoding.encodeLength(0));
assertArrayEquals(new byte[] { 1 } /* [1] */, ShortvecEncoding.encodeLength(1));
assertArrayEquals(new byte[] { 5 } /* [5] */, ShortvecEncoding.encodeLength(5));
Expand Down