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

Cicd tests #287

Merged
merged 5 commits into from
Aug 30, 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
7 changes: 7 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CYPRUS1_PRIVKEY_1="0x88391c9aa998c810322838623728b5421ec906171a19ea15da25e0d15d0cfa09"
CYPRUS1_ADDR_1="0x00048b6FE7D7f18b142ea2133A6B8F42B75d5e3F"
CYPRUS1_PRIVKEY_2="0xc44d26c6f48e7990d124395a9b3584627a2dbc862d6d4dc71af6e83ed9220b86"
CYPRUS1_ADDR_2="0x00055f033Dc133eB44D8690836c0d5a97fF3ad3a"

PRIMEURL="http://localhost:9100/"
CYPRUS1URL="http://localhost:9200/"
24 changes: 24 additions & 0 deletions .github/workflows/dev-build-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Manual Dev Workflow
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to use'
required: true
default: 'main'
jobs:
call-common-workflow:
uses: dominant-strategies/quai-cicd/.github/workflows/deploy-dev-common.yml@main
with:
needs_build: true
install_command: "npm ci"
build_command: "npm run build-clean && npm run test-unit && npm run test-integ-containers"
cloud_deploy: false
skip_deploy: true
update_version: false
needs_docker: false
include_chart: false
needs_docker_compose: true
secrets:
GH_PAT: ${{ secrets.GH_PAT }}
BUILD_ARGS: ''
5 changes: 3 additions & 2 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ name: Auto Dev Workflow
on:
pull_request:
types: [closed]
branches: [ "master" ]
branches: [ "alpha" ]
jobs:
call-common-workflow:
uses: dominant-strategies/quai-cicd/.github/workflows/deploy-dev-common.yml@main
with:
needs_build: true
install_command: "npm ci"
build_command: "npm run build-clean"
build_command: "npm run build-clean && npm run test-unit && npm run test-integ-containers"
cloud_deploy: false
skip_deploy: true
update_version: false
needs_docker: false
include_chart: false
needs_docker_compose: true
secrets:
GH_PAT: ${{ secrets.GH_PAT }}
BUILD_ARGS: ''
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ dist/*.gz
.idea/**
lib/commonjs/**
lib/esm/**
.env
.env*
!.env.test
.DS_Store
quai-local-node*
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@
"clean": "rm -rf dist lib/esm lib/commonjs && cp -r misc/basedirs/* .",
"update-symlink": "npm run clean && npm run build-all && npm rm -g quais-6 -g && npm link",
"stats": "echo 'Dependencies' && npm ls --all --omit=dev",
"test": "npm run test-esm",
"test": "NODE_ENV=test npm run test-esm",
"test-containers": "npm run containers-up && NODE_ENV=test npm run test; npm run containers-down",
"test-integ-containers": "npm run containers-up && NODE_ENV=test npm run test-integ; npm run containers-down",
"containers-up": "./start-test-containers.sh",
"containers-down": "./stop-test-containers.sh",
"test-browser": "node lib/esm/_tests/browser/test-browser.js",
"test-commonjs": "mocha --reporter ./reporter.cjs ./lib/commonjs/_tests/**/*.test.js",
"test-unit": "mocha --reporter ./reporter.cjs ./lib/commonjs/_tests/unit/*.unit.test.js",
Expand Down
7 changes: 6 additions & 1 deletion src/_tests/integration/create-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { isError, JsonRpcProvider } from '../../index.js';

import type { AbstractProvider } from '../../index.js';
import dotenv from 'dotenv';
dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });

interface ProviderCreator {
name: string;
Expand Down
11 changes: 7 additions & 4 deletions src/_tests/integration/providerdata.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import axios from 'axios';
import { stall } from '../utils.js';
import dotenv from 'dotenv';
import { Shard } from '../../constants/index.js';
dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });
// import {
// networkFeatureAtBlock, networkNames,
// testAddress, testBlock, testReceipt, testTransaction
Expand All @@ -22,9 +27,7 @@ dotenv.config();
//setupProviders();

const providerC1 = new quais.JsonRpcProvider(process.env.RPC_URL);
const privateKey = process.env.CYPRUS1PK;
console.log(privateKey);
const wallet = new quais.Wallet(process.env.CYPRUS1PK || '', providerC1);
const wallet = new quais.Wallet(process.env.CYPRUS1_PRIVKEY_1 || '', providerC1);
const destinationC1 = '0x0047f9CEa7662C567188D58640ffC48901cde02a';
const destinationC2 = '0x011ae0a1Bd5B71b4F16F8FdD3AEF278C3D042449';

Expand Down
7 changes: 6 additions & 1 deletion src/_tests/integration/providererrror.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { stall } from '../utils.js';

import dotenv from 'dotenv';
import { QuaiTransactionResponse } from '../../providers/provider.js';
dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });

type TestCustomError = {
name: string;
Expand Down
7 changes: 6 additions & 1 deletion src/_tests/integration/qrc20.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { quais, Contract } from '../../index.js';
import dotenv from 'dotenv';
import QRC20 from './contracts/QRC20.js';

dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });

describe('Tests ERC20 contract deployment and integration', function () {
this.timeout(120000);
Expand Down
7 changes: 6 additions & 1 deletion src/_tests/integration/rpcendpoints.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import assert from 'assert';
import dotenv from 'dotenv';
dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });

import { JsonRpcProvider, Shard } from '../../index.js';

Expand Down
7 changes: 6 additions & 1 deletion src/_tests/integration/sendquai.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { JsonRpcProvider, Wallet } from '../../index.js';

import dotenv from 'dotenv';
import { QuaiTransactionResponse } from '../../providers/provider.js';
dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });

const testCases = [
{
Expand Down
7 changes: 6 additions & 1 deletion src/_tests/integration/simplestorage.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { JsonRpcProvider, Wallet, ContractFactory, Contract, ContractRunner } fr
import SimpleStorageContract from './contracts/SimpleStorageContract.js';

import dotenv from 'dotenv';
dotenv.config();
const env = process.env.NODE_ENV || 'development';

dotenv.config({ path: `.env.${env}` });

// Or fallback to .env if NODE_ENV specific file doesn't exist
dotenv.config({ path: `.env`, override: false });

describe('Test Contract SimpleStorage', function () {
this.timeout(60000);
Expand Down
2 changes: 1 addition & 1 deletion src/_tests/unit/formatter.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { expect } from 'chai';
import assert from 'assert';
import { formatTransactionReceipt } from '../../providers/format';
import { formatTransactionReceipt } from '../../providers/format.js';

// Mock objects similar to what would be returned by your JSON RPC response
const inZoneTxReceipt = {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import {
PollingTransactionSubscriber,
} from './subscriber-polling.js';
import { getNodeLocationFromZone, getZoneFromNodeLocation } from '../utils/shards.js';
import { fromShard } from '../constants/shards';
import { fromShard } from '../constants/shards.js';

type Timer = ReturnType<typeof setTimeout>;

Expand Down
70 changes: 61 additions & 9 deletions src/providers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
EtxParams,
QiTransactionResponseParams,
QuaiTransactionResponseParams,
ExternalTransactionResponseParams,
} from './formatting.js';

const BN_0 = BigInt(0);
Expand Down Expand Up @@ -208,7 +209,7 @@ const _formatBlock = object({
if (typeof tx === 'string') {
return formatHash(tx);
}
return formatTransactionResponse(tx);
return formatExternalTransactionResponse(tx);
}),
hash: formatHash,
header: _formatHeader,
Expand All @@ -229,17 +230,22 @@ const _formatBlock = object({

export function formatBlock(value: any): BlockParams {
const result = _formatBlock(value);
result.transactions = value.transactions.map((tx: string | TransactionResponseParams) => {
if (typeof tx === 'string') {
return tx;
}
return formatTransactionResponse(tx);
});
result.extTransactions = value.extTransactions.map((tx: string | TransactionResponseParams) => {
result.transactions = value.transactions.map(
(tx: string | TransactionResponseParams | ExternalTransactionResponseParams) => {
if (typeof tx === 'string') {
return tx;
}
if ('originatingTxHash' in tx) {
return formatExternalTransactionResponse(tx);
}
return formatTransactionResponse(tx);
},
);
result.extTransactions = value.extTransactions.map((tx: string | ExternalTransactionResponseParams) => {
if (typeof tx === 'string') {
return tx;
}
return formatTransactionResponse(tx);
return formatExternalTransactionResponse(tx);
});
return result;
}
Expand Down Expand Up @@ -321,6 +327,51 @@ export function formatTransactionReceipt(value: any): TransactionReceiptParams {
return result;
}

export function formatExternalTransactionResponse(value: any): ExternalTransactionResponseParams {
const result = object(
{
hash: formatHash,
type: (value: any) => {
if (value === '0x' || value == null) {
return 0;
}
return parseInt(value, 16);
},
accessList: allowNull(accessListify, null),
blockHash: allowNull(formatHash, null),
blockNumber: allowNull((value: any) => (value ? parseInt(value, 16) : null), null),
index: allowNull((value: any) => (value ? BigInt(value) : null), null),
from: allowNull(getAddress, null),
sender: allowNull(getAddress, null),
maxPriorityFeePerGas: allowNull((value: any) => (value ? BigInt(value) : null)),
maxFeePerGas: allowNull((value: any) => (value ? BigInt(value) : null)),
gasLimit: allowNull((value: any) => (value ? BigInt(value) : null), null),
to: allowNull(getAddress, null),
value: allowNull((value: any) => (value ? BigInt(value) : null), null),
nonce: allowNull((value: any) => (value ? parseInt(value, 10) : null), null),
creates: allowNull(getAddress, null),
chainId: allowNull((value: any) => (value ? BigInt(value) : null), null),
isCoinbase: allowNull((value: any) => (value ? parseInt(value, 10) : null), null),
originatingTxHash: allowNull(formatHash, null),
etxIndex: allowNull((value: any) => (value ? parseInt(value, 10) : null), null),
etxType: allowNull((value: any) => value, null),
data: (value: any) => value,
},
{
data: ['input'],
gasLimit: ['gas'],
index: ['transactionIndex'],
},
)(value) as ExternalTransactionResponseParams;

// 0x0000... should actually be null
if (result.blockHash && getBigInt(result.blockHash) === BN_0) {
result.blockHash = null;
}

return result;
}

export function formatTransactionResponse(value: any): TransactionResponseParams {
// Determine if it is a Quai or Qi transaction based on the type
const transactionType = parseInt(value.type, 16);
Expand Down Expand Up @@ -352,6 +403,7 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
nonce: allowNull((value: any) => (value ? parseInt(value, 10) : null), null),
creates: allowNull(getAddress, null),
chainId: allowNull((value: any) => (value ? BigInt(value) : null), null),
etxType: allowNull((value: any) => value, null),
data: (value: any) => value,
},
{
Expand Down
Loading
Loading