Skip to content

Commit f050b62

Browse files
committed
unit tests should work for both geth and loom environments
1 parent 7458801 commit f050b62

7 files changed

Lines changed: 54 additions & 7 deletions

File tree

compose/circleci-es.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ services:
2929
command: sh -c 'while sleep 3600; do :; done'
3030
links:
3131
- redis_db
32-
- geth-poa
32+
- loom
3333
- elasticsearch
3434
- sftp
3535
- minio
@@ -47,3 +47,9 @@ services:
4747
- S3_ENDPOINT=http://minio:9000
4848
- S3_ACCESSKEY=myMinioAccessKey
4949
- S3_SECRETKEY=myMinioSecretKey
50+
- GETH_NODE=http://loom:46658/eth
51+
- LOOM_ENABLED=true
52+
- LOOM_CHAIN_ID_STRING=default
53+
- LOOM_CHAIN_ID_NUMBER=3657971041736948
54+
- LOOM_DEPLOY_KEY=0x0000000000000000000000000000000000000000000000000000000000000001
55+

compose/circleci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,31 @@ services:
3232
- LOOM_CHAIN_ID_STRING=default
3333
- LOOM_CHAIN_ID_NUMBER=3657971041736948
3434
- LOOM_DEPLOY_KEY=0x0000000000000000000000000000000000000000000000000000000000000001
35+
36+
37+
rpc-geth:
38+
build:
39+
context: ../
40+
target: test
41+
image: engine-node-test
42+
# command: sleep infinity
43+
command: sh -c 'while sleep 3600; do :; done'
44+
links:
45+
- redis_db
46+
- geth-poa
47+
- sftp
48+
- minio
49+
- psql
50+
environment:
51+
- ENV=test
52+
- SFTP_DRIVER_TESTS
53+
- SFTP_HOST=sftp
54+
- SFTP_PORT=22
55+
- SFTP_USER=shipchain_user
56+
- SFTP_PASS=shipchain_password
57+
- S3_DRIVER_TESTS
58+
- S3_BUCKET=my-test-bucket
59+
- S3_ENDPOINT=http://minio:9000
60+
- S3_ACCESSKEY=myMinioAccessKey
61+
- S3_SECRETKEY=myMinioSecretKey
62+
- GETH_NODE=http://geth-poa:8545

compose/dev-lite.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ services:
1818
- /data/shipchain/engine/loom.app.db:/app/app.db
1919
- /data/shipchain/engine/loom.evm.db:/app/evm.db
2020
- /data/shipchain/engine/loom.receipts_db:/app/receipts_db
21+
ports:
22+
- 46658:46658
2123

2224

2325
psql:

config/custom-environment-variables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default {
2121
"DEPLOY_PRIVATE_KEY": "DEPLOY_PRIVATE_KEY",
2222
"ELASTICSEARCH_URL": "ELASTICSEARCH_URL",
2323
"ETHERSCAN_API_KEY": "ETHERSCAN_API_KEY",
24+
"ES_TEST_NODE_URL": "ES_TEST_NODE_URL",
2425
"FORCE_LATEST_LOAD_CONTRACT_VERSION" : "FORCE_LATEST_LOAD_CONTRACT_VERSION",
2526
"FORCE_LATEST_NOTARY_CONTRACT_VERSION" : "FORCE_LATEST_NOTARY_CONTRACT_VERSION",
2627
"GETH_NODE": "GETH_NODE",

rpc/__tests__/wallet.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import { RPCWallet } from '../wallet';
3232
import { Wallet } from "../../src/entity/Wallet";
3333
import { EncryptorContainer } from '../../src/entity/encryption/EncryptorContainer';
34+
import { LoomHooks } from "../../src/eth/LoomHooks";
3435

3536
export const RPCWalletTests = async function() {
3637

@@ -165,7 +166,11 @@ export const RPCWalletTests = async function() {
165166
wallet: imported.wallet.id,
166167
});
167168
expect(response.success).toBeTruthy();
168-
expect(response.ether).toEqual('0');
169+
if (LoomHooks.enabled) {
170+
expect(response.ether).toEqual('0');
171+
} else {
172+
expect(response.ether).toEqual('158456325028527356587087900672');
173+
}
169174
expect(response.ship).toEqual('500000000000000000000');
170175
} catch (err) {
171176
fail(`Should not have thrown [${err}]`);

src/__tests__/contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ export const ContractEntityTests = async function() {
8181

8282
expect(new_other_balance).toEqual(ethereumService.unitToWei(100, 'ether'));
8383
},
84-
30000,
84+
60000,
8585
);
8686
};

src/__tests__/eventsubscriptions.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Network, Project } from '../entity/Contract';
2222
import { EventSubscription, EventSubscriberAttrs } from '../entity/EventSubscription';
2323
import { EncryptorContainer } from '../entity/encryption/EncryptorContainer';
2424
import { AbstractEthereumService } from "../eth/AbstractEthereumService";
25+
import { LoomHooks } from "../eth/LoomHooks";
2526

2627
const request = require('request');
2728
const config = require('config');
@@ -89,6 +90,7 @@ export const EventSubscriptionEntityTests = async function() {
8990

9091
const subscriberAttrs = new EventSubscriberAttrs();
9192
subscriberAttrs.project = 'ShipToken';
93+
subscriberAttrs.version = '1.0.0';
9294
subscriberAttrs.url = ES_NODE;
9395
subscriberAttrs.receiverType = 'ELASTIC';
9496

@@ -98,9 +100,12 @@ export const EventSubscriptionEntityTests = async function() {
98100
const ETH = 10 ** 18;
99101
const TOTAL = 500 * SHIP;
100102

101-
expect(Number(await local.ShipToken.call_static('balanceOf', [await owner.asyncEvmAddress]))).toEqual(TOTAL);
103+
const ownerBalance = await local.ShipToken.call_static('balanceOf', [await owner.asyncEvmAddress]);
104+
expect(Number(ownerBalance)).toEqual(TOTAL);
102105

103-
expect(Number(await ethereumService.getBalance(await owner.asyncEvmAddress))).toEqual(5 * ETH);
106+
if (!LoomHooks.enabled) {
107+
expect(Number(await ethereumService.getBalance(await owner.asyncEvmAddress))).toEqual(5 * ETH);
108+
}
104109

105110
const txParams = await owner.add_tx_params(
106111
network,
@@ -148,9 +153,9 @@ export const EventSubscriptionEntityTests = async function() {
148153

149154
//console.log('ElasticSearch Events:', results)
150155

151-
expect(results['hits']['total']).toEqual(4);
156+
expect(results['hits']['total']['value']).toEqual(4);
152157

153158
},
154-
30000, // This one can be a bit slow...
159+
60000, // This one can be a bit slow...
155160
);
156161
};

0 commit comments

Comments
 (0)