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

add new test cases #33

Merged
merged 2 commits into from
Jun 26, 2024
Merged
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
23 changes: 23 additions & 0 deletions src/__tests__/integration/ethAccounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_accounts', () => {
it('should return an array of eth accounts', async () => {
const response = await request(extendedServer)
.post('/')
.send(
{
method: "eth_accounts",
params: ["", "latest"],
id: 1,
jsonrpc: "2.0"
}
);

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toContain('0x407d73d8a49eeb85d32cf465507dd71d507100c1');
});
});
});
23 changes: 23 additions & 0 deletions src/__tests__/integration/ethBlockNumber.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_blockNumber', () => {
it('should return the block number', async () => {
const response = await request(extendedServer)
.post('/')
.send(
{
method: "eth_blockNumber",
params: ["", "latest"],
id: 1,
jsonrpc: "2.0"
}
);

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toMatch(/^0x[0-9a-fA-F]+$/);
});
});
});
23 changes: 23 additions & 0 deletions src/__tests__/integration/ethCoinbase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_coinbase', () => {
it('should return false once not an active node', async () => {
const response = await request(extendedServer)
.post('/')
.send(
{
method: "eth_coinbase",
params: ['', "latest"],
id: 1,
jsonrpc: "2.0"
}
);

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toBe('');
});
});
});
18 changes: 4 additions & 14 deletions src/__tests__/integration/ethGasPrice.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@

import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {


describe('eth_gasPrice', () => {
it('should return gas price', async () => {
let result = null;
let error = null;

const callback = (err: any, res: any) => {
error = err;
result = res;
};

const response = await request(extendedServer)
.post('/')
.send({
jsonrpc: '2.0',
id: 1,
method: 'eth_gasPrice',
params: [[], callback],
params: []
});

expect(response.statusCode).toBe(200);
expect(response.body).toBeDefined();
expect(response.body.result).toBe(result);
expect(response.body.result).toBeDefined();
expect(response.body.result).toMatch(/^0x[0-9a-fA-F]+$/);
});
});
});
});
28 changes: 14 additions & 14 deletions src/__tests__/integration/ethGetBalance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { extendedServer } from '../../server';
describe('JSON-RPC Methods', () => {
describe('eth_getBalance', () => {
it('should return the correct balance for a valid address', async () => {
const address = '0xf1a66ee4db3bfec6a4233bd10e587dacdae985a6';
const address = '0x4a372F3F5cFa12Ce491106BDD82735764ea29D62';
const response = await request(extendedServer)
.post('/')
.send(
Expand All @@ -21,20 +21,20 @@ describe('JSON-RPC Methods', () => {

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toBe('0x0');
expect(response.body.result).toMatch(/^0x[0-9a-fA-F]+$/);
});

// it('should return zero if the address has no transactions', async () => {
// const response = await request(extendedServer)
// .post('/')
// .send({
// jsonrpc: '2.0',
// method: 'eth_getTransactionCount',
// params: ['0x742d35Cc6634C0532925a3b844Bc454e4438f44e', 'latest'],
// id: 4,
// });
// expect(response.status).toBe(200);
// expect(response.body.result).toBe('0x0');
// });
it('should return zero if the address has no transactions', async () => {
const response = await request(extendedServer)
.post('/')
.send({
jsonrpc: '2.0',
method: 'eth_getTransactionCount',
params: ['0x0D0668F67Ed7Ce0ce7D7AD234020054E9d5995C2', 'latest'],
id: 4,
});
expect(response.status).toBe(200);
expect(response.body.result).toBe('0x0');
});
});
});
26 changes: 26 additions & 0 deletions src/__tests__/integration/ethGetStorageAt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_getStorageAt', () => {
it('should return the storage value at a given position', async () => {
const response = await request(extendedServer)
.post('/')
.send({
jsonrpc: '2.0',
id: 1,
method: 'eth_getStorageAt',
params: [
'0xb6da4e0870f18247dafc9495652c394c3c8c60b8',
'0x0',
'latest'
]
});

expect(response.statusCode).toBe(200);
expect(response.body).toBeDefined();
expect(response.body.result).toMatch(/^0x[0-9a-fA-F]*$/); // Matches any hex string
});

});
});
23 changes: 23 additions & 0 deletions src/__tests__/integration/ethHashRate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_hashrate', () => {
it('should return the hashrate', async () => {
const response = await request(extendedServer)
.post('/')
.send(
{
method: "eth_hashrate",
params: ['', "latest"],
id: 1,
jsonrpc: "2.0"
}
);

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toBe('0x38a');
});
});
});
23 changes: 23 additions & 0 deletions src/__tests__/integration/ethMining.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_mining', () => {
it('should return mining as true', async () => {
const response = await request(extendedServer)
.post('/')
.send(
{
method: "eth_mining",
params: ['', "latest"],
id: 1,
jsonrpc: "2.0"
}
);

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toBe(true);
});
});
});
23 changes: 23 additions & 0 deletions src/__tests__/integration/ethProtcolVersion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from 'supertest';
import { extendedServer } from '../../server';

describe('JSON-RPC Methods', () => {
describe('eth_protocolVersion', () => {
it('should return the protocol version', async () => {
const response = await request(extendedServer)
.post('/')
.send(
{
method: "eth_protocolVersion",
params: ['', "latest"],
id: 1,
jsonrpc: "2.0"
}
);

expect(response.status).toBe(200);
expect(response.body.result).toBeDefined();
expect(response.body.result).toBe('54');
});
});
});
9 changes: 3 additions & 6 deletions src/__tests__/integration/ethSignTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/__tests__/integration/api/eth_signTransaction.test.ts
import request from 'supertest';
import { extendedServer } from '../../server';

Expand All @@ -13,9 +12,9 @@ describe('POST /api/method eth_signTransaction', () => {
{
from: '0xa4c0aadcce9c04fe8b833279b0198d4ae29d76a7',
to: '0x510e84aa16ab92752451a2763352681624c75ebe',
gas: '0x76c0', // 30400
gasPrice: '0x9184e72a000', // 10000000000000
value: '0x9184e72a', // 2441406250
gas: '0x76c0',
gasPrice: '0x9184e72a000',
value: '0x9184e72a',
data: '0x0',
},
],
Expand All @@ -25,6 +24,4 @@ describe('POST /api/method eth_signTransaction', () => {
expect(response.body).toHaveProperty('result');
expect(response.body.result).toBe('0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b');
});


});
105 changes: 0 additions & 105 deletions src/__tests__/integration/eth_blockNumber.test.ts

This file was deleted.