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

Revert ledger bug fix #56

Merged
merged 5 commits into from
Oct 5, 2022
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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@
},
"devDependencies": {
"@types/jest": "27.0.3",
"@types/jest-expect-message": "^1.1.0",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"@typescript-eslint/typescript-estree": "^5.37.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest-expect-message": "^1.1.3",
"lerna": "^3.22.1",
"prettier": "2.4.1",
"ts-jest": "^26.4.4",
"typescript": "^4.0.5"
},
"resolutions": {
"@cosmjs/[email protected]": "npm:@regen-network/[email protected]"
},
"packageManager": "[email protected]"
}
34 changes: 17 additions & 17 deletions packages/api/e2e/amino.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

const TEST_ADDRESS = 'regen1m0qh5y4ejkz3l5n6jlrntxcqx9r0x9xjv4vpcp';
const TEST_BUYER_ADDRESS = 'regen13hu59094gzfcpxl58fcz294p5g5956utwlpqll';
const REDWOOD_NODE_TM_URL = 'http://redwood.regen.network:26657/';
const NODE_URL = process.env.NODE_URL || 'http://localhost:26657';
const TEST_FEE: StdFee = {
amount: [
{
Expand All @@ -41,8 +41,8 @@ const TEST_FEE: StdFee = {
gas: '200000',
};
const TEST_MEMO = `regen-js v${process.env.npm_package_version} tests`;
const TEST_BATCH_DENOM = 'C01-001-20170606-20210601-007';
const TEST_CLASS_ID = 'C22';
const TEST_BATCH_DENOM = 'C01-001-20200101-20210101-001';
const TEST_CLASS_ID = 'C01';
const MIN_CREDIT_AMOUNT = '0.000001';

const connect = async (): Promise<RegenApi> => {
Expand All @@ -57,7 +57,7 @@ const connect = async (): Promise<RegenApi> => {
return RegenApi.connect({
connection: {
type: 'tendermint',
endpoint: REDWOOD_NODE_TM_URL,
endpoint: NODE_URL,
signer,
},
});
Expand All @@ -81,7 +81,7 @@ const runAminoTest = async (
if (signedTxBytes) {
txRes = await msgClient?.broadcast(signedTxBytes);
expect(txRes).toBeTruthy();
expect(txRes?.code).toBe(0);
expect(txRes?.code, txRes?.rawLog).toBe(0);
}
};

Expand Down Expand Up @@ -139,7 +139,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {

await runAminoTest(msgClient, TEST_MSG_SEND);
});
xit('should sign and broadcast MsgCreateClass', async () => {
it('should sign and broadcast MsgCreateClass', async () => {
const { msgClient } = await connect();

const TEST_MSG_CREATE_CLASS = MsgCreateClass.fromPartial({
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {

const TEST_MSG_CREATE_BATCH = MsgCreateBatch.fromPartial({
issuer: TEST_ADDRESS,
projectId: 'C22-001',
projectId: 'C01-001',
issuance: [
{
recipient: TEST_ADDRESS,
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {

const TEST_MSG_CREATE_BATCH = MsgCreateBatch.fromPartial({
issuer: TEST_ADDRESS,
projectId: 'C22-001',
projectId: 'C01-001',
issuance: [
{
recipient: TEST_ADDRESS,
Expand Down Expand Up @@ -265,7 +265,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
});
});
xdescribe('Signing and broadcasting Basket txs using legacy amino sign mode', () => {
xit('should sign and broadcast MsgCreate', async () => {
it('should sign and broadcast MsgCreate', async () => {
const { msgClient } = await connect();

const basketName = 'TEST' + (Date.now() % 1000);
Expand All @@ -276,7 +276,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
exponent: 7,
disableAutoRetire: false,
creditTypeAbbrev: 'C',
allowedClasses: ['C14', 'C13'],
allowedClasses: ['C01'],
dateCriteria: undefined,
fee: [
{
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
await runAminoTest(msgClient, TEST_BASKET_MSG_TAKE);
});
});
xdescribe('Signing and broadcasting Marketplace txs using legacy amino sign mode', () => {
describe('Signing and broadcasting Marketplace txs using legacy amino sign mode', () => {
it('should sign and broadcast MsgSell', async () => {
const { msgClient } = await connect();
const sellOrder = {
Expand Down Expand Up @@ -350,14 +350,14 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {

await runAminoTest(msgClient, TEST_MSG_SELL);
});
xit('should sign and broadcast MsgCancelSellOrder', async () => {
it('should sign and broadcast MsgCancelSellOrder', async () => {
// This test passes, but it needs a real sellOrderId generated by the same address.
// If sell order 50 doesn't work, run the MsgSell test to get a new sellOrderId to cancel.
const { msgClient } = await connect();

const TEST_MSG_CANCEL = MsgCancelSellOrder.fromPartial({
seller: TEST_ADDRESS,
sellOrderId: Long.fromValue(52), // If this id doesn't work, run the MsgSell test to get a new sellOrderId to cancel
sellOrderId: Long.fromValue(1), // If this id doesn't work, run the MsgSell test to get a new sellOrderId to cancel
});

await runAminoTest(msgClient, TEST_MSG_CANCEL);
Expand All @@ -375,7 +375,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
return RegenApi.connect({
connection: {
type: 'tendermint',
endpoint: REDWOOD_NODE_TM_URL,
endpoint: NODE_URL,
signer: buyerSigner,
},
});
Expand All @@ -386,7 +386,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
buyer: TEST_BUYER_ADDRESS,
orders: [
{
sellOrderId: '50',
sellOrderId: '2',
quantity: '.000001',
bidPrice: { denom: 'uregen', amount: '1000000' },
disableAutoRetire: false,
Expand All @@ -410,7 +410,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
return RegenApi.connect({
connection: {
type: 'tendermint',
endpoint: REDWOOD_NODE_TM_URL,
endpoint: NODE_URL,
signer: buyerSigner,
},
});
Expand All @@ -421,7 +421,7 @@ describe('RegenApi with tendermint connection - Amino Tests', () => {
buyer: TEST_BUYER_ADDRESS,
orders: [
{
sellOrderId: '12', // sell order with disableAutoRetire: true
sellOrderId: '2', // sell order with disableAutoRetire: true
quantity: '.000001',
bidPrice: { denom: 'uregen', amount: '13000000' },
disableAutoRetire: true,
Expand Down
95 changes: 52 additions & 43 deletions packages/api/e2e/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { DirectSecp256k1HdWallet, OfflineSigner } from '@cosmjs/proto-signing';
import { DeliverTxResponse } from '@cosmjs/stargate';
import { RegenApi } from '../src/api';
import { QueryClientImpl } from '../src/generated/cosmos/bank/v1beta1/query';
import { MsgSend } from '../src/generated/cosmos/bank/v1beta1/tx';
import { ServiceClientImpl } from '../src/generated/cosmos/tx/v1beta1/service';

const TEST_ADDRESS = 'regen1df675r9vnf7pdedn4sf26svdsem3ugavgxmy46';
const REDWOOD_NODE_TM_URL = 'http://redwood.regen.network:26657/';
const NODE_URL = process.env.NODE_URL || 'http://localhost:26657';
const TEST_FEE = {
amount: [
{
Expand All @@ -18,63 +17,44 @@ const TEST_FEE = {
};
const TEST_MEMO = `regen-js v${process.env.npm_package_version} tests`;
// This test msg just sends tokens to the same address
const TEST_MSG = MsgSend.fromPartial({
fromAddress: TEST_ADDRESS,
toAddress: TEST_ADDRESS,
amount: [{ amount: '1000', denom: 'uregen' }],
});

const connect = async (): Promise<RegenApi> => {
const mnemonic = // mnemonic for TEST_ADDRESS
'coast scheme approve soccer juice wealth bunker state fetch warrior inmate belt';

const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: 'regen',
});

const connect = async (signer: OfflineSigner): Promise<RegenApi> => {
return RegenApi.connect({
connection: {
type: 'tendermint',
endpoint: REDWOOD_NODE_TM_URL,
endpoint: NODE_URL,
signer,
},
});
};

let api: RegenApi;
let signerAddress: string;
let testTxHash: string | undefined;

describe('RegenApi with tendermint connection', () => {
beforeAll(async () => {
api = await connect();
});
describe('Querying', () => {
it('should fetch balances using tendermint query client', async () => {
const bankClient = new QueryClientImpl(api.queryClient);

const res = await bankClient.AllBalances({
address: TEST_ADDRESS,
});
expect(res.balances.length).toBeGreaterThanOrEqual(1);
const mnemonic = // mnemonic for signerAddress
'time dice choose cabbage suit panic silly cattle picture auto grab hole';
const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: 'regen',
});
api = await connect(signer);

it('should fetch a tx using tendermint service client', async () => {
const redwoodTxHash =
'F6A31AB068F49C5719ECB3793E0C3C4412EDD1F0C3D3C954EE0D9B1C81A0BEC8';
const serviceClient = new ServiceClientImpl(api.queryClient);

const res = await serviceClient.GetTx({
hash: redwoodTxHash,
});
expect(res.txResponse).toBeTruthy();
expect(res.txResponse?.data).toBeTruthy();
expect(res.txResponse?.txhash).toEqual(redwoodTxHash);
});
const accounts = await signer.getAccounts();
signerAddress = accounts[0].address;
});
describe('Signing and broadcasting txs', () => {
it('should get data back with a signing client - signed transaction', async () => {
const signedTxBytes = await api.msgClient?.sign(
TEST_ADDRESS,
[TEST_MSG],
signerAddress,
[
MsgSend.fromPartial({
fromAddress: signerAddress,
toAddress: signerAddress,
amount: [{ amount: '1000', denom: 'uregen' }],
}),
],
TEST_FEE,
TEST_MEMO,
);
Expand All @@ -87,16 +67,45 @@ describe('RegenApi with tendermint connection', () => {
const signingClient = api.msgClient;

const signedTxBytes = await api.msgClient?.sign(
TEST_ADDRESS,
[TEST_MSG],
signerAddress,
[
MsgSend.fromPartial({
fromAddress: signerAddress,
toAddress: signerAddress,
amount: [{ amount: '1000', denom: 'uregen' }],
}),
],
TEST_FEE,
TEST_MEMO,
);
expect(signedTxBytes).toBeTruthy();
if (signedTxBytes) {
txRes = await signingClient?.broadcast(signedTxBytes);
expect(txRes).toBeTruthy();
expect(txRes?.transactionHash).toBeTruthy();
testTxHash = txRes?.transactionHash;
}
});
});
describe('Querying', () => {
it('should fetch balances using tendermint query client', async () => {
const bankClient = new QueryClientImpl(api.queryClient);

const res = await bankClient.AllBalances({
address: signerAddress,
});
expect(res.balances.length).toBeGreaterThanOrEqual(1);
});

it('should fetch a tx using tendermint service client', async () => {
const serviceClient = new ServiceClientImpl(api.queryClient);

const res = await serviceClient.GetTx({
hash: testTxHash,
});
expect(res.txResponse).toBeTruthy();
expect(res.txResponse?.data).toBeTruthy();
expect(res.txResponse?.txhash).toEqual(testTxHash);
});
});
});
7 changes: 7 additions & 0 deletions packages/api/e2e/regen-ledger/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export REGEN_BIN="/path/to/regen"
export REGEN_HOME="./.regen"
export REGEN_CHAIN_ID="regen-js-e2e"

# Testing mnemonics -- DO NOT USE IN PRODUCTION
export REGEN_MNEMONIC_ADDR1="time dice choose cabbage suit panic silly cattle picture auto grab hole"
export REGEN_MNEMONIC_ADDR2="seminar throw sorry nerve outer lottery stuff blush couple medal wire pink"
2 changes: 2 additions & 0 deletions packages/api/e2e/regen-ledger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.regen
.env
63 changes: 63 additions & 0 deletions packages/api/e2e/regen-ledger/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
rm -rf $REGEN_HOME

alias regen="$REGEN_BIN --home $REGEN_HOME"
regen config keyring-backend test
regen config node http://localhost:26657
regen config chain-id $REGEN_CHAIN_ID
regen config broadcast-mode block
regen config output json

regen init test_moniker --chain-id $REGEN_CHAIN_ID 2>&1 | jq -r '"Created genesis. chain-id: \(.chain_id), moniker: \(.moniker)"'

if [[ $(uname -s) == 'Darwin' ]]; then
# change stake denom to uregen
sed -i "" "s/stake/uregen/g" $REGEN_HOME/config/genesis.json
# set min gas price
sed -i "" "s/minimum-gas-prices = \"\"/minimum-gas-prices = \"0.025uregen\"/g" $REGEN_HOME/config/app.toml
# decrease block-time so tests run faster
sed -i "" "s/timeout_commit = \"5s\"/timeout_commit = \"500ms\"/g" $REGEN_HOME/config/config.toml
else
# change stake denom to uregen
sed -i "s/stake/uregen/g" $REGEN_HOME/config/genesis.json
# set min gas price
sed -i "s/minimum-gas-prices = \"\"/minimum-gas-prices = \"0.025uregen\"/g" $REGEN_HOME/config/app.toml
# decrease block-time so tests run faster
sed -i "s/timeout_commit = \"5s\"/timeout_commit = \"500ms\"/g" $REGEN_HOME/config/config.toml
fi

if ! [ -z "$REGEN_MNEMONIC_ADDR1" ]; then
echo "Adding key to keyring for account name: addr1"
echo $REGEN_MNEMONIC_ADDR1 | regen keys add addr1 --recover > /dev/null
regen add-genesis-account addr1 50000000000uregen --keyring-backend test
regen gentx addr1 40000000000uregen --ip 127.0.0.1
else
echo "No \$REGEN_MNEMONIC_ADDR1 provided."
fi


if ! [ -z "$REGEN_MNEMONIC_ADDR2" ]; then
echo "Adding key to keyring for account name: addr2"
echo $REGEN_MNEMONIC_ADDR2 | regen keys add addr2 --recover > /dev/null
regen add-genesis-account addr2 10000000000uregen --keyring-backend test
fi

regen collect-gentxs 2>&1 | jq -r '"Collecting gentxs from \(.gentxs_dir)"'

# Make sure we kill the regen process if our script exits while node is running
# in the background
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# Start regen chain and immediately move it to the background
echo "Starting up regen node..."
regen start --log_level warn &
REGEN_PID=$!

# Sleep for regen node to full boot up
sleep 3

# run initialization of credit classes, projects, batches for regen-js/e2e tests
./setup-amino-suite.sh

# wait again on the regen node process so it can be terminated with ctrl+C
wait $REGEN_PID

Loading