Skip to content

Commit

Permalink
wip: refact test dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Nov 28, 2023
1 parent 13eff2d commit 19c0ccf
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 431 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.vscode
.idea
*.code-workspace
data


# Build
bin
Expand All @@ -35,9 +35,6 @@ coverage.txt
profile.out
sim_log_file

_build
.testnet

# Vagrant
.vagrant/
*.box
Expand All @@ -60,3 +57,5 @@ dependency-graph.png
scripts/tests/ibc-hooks/counter/target
scripts/tests/vesting-accounts/.vesting-periods.json
node_modules
test-data
chain-upgrade-data
35 changes: 0 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,41 +196,6 @@ install: go.sum

.PHONY: build build-linux install


###############################################################################
### Integration Tests ###
###############################################################################

integration-test-all: init-test-framework \
test-ibc-hooks \
test-tokenfactory

init-test-framework: clean-testing-data install
@echo "Initializing both blockchains..."
./scripts/tests/init-test-framework.sh
@echo "Testing relayer..."
./scripts/tests/relayer/interchain-acc-config/rly-init.sh

test-tokenfactory:
@echo "Testing tokenfactory..."
./scripts/tests/tokenfactory/tokenfactory.sh

test-chain-upgrade:
@echo "Testing software upgrade..."
bash ./scripts/tests/chain-upgrade/chain-upgrade.sh

clean-testing-data:
@echo "Killing terrad and removing previous data"
-@pkill terrad 2>/dev/null
-@pkill rly 2>/dev/null
-@pkill terrad_new 2>/dev/null
-@pkill terrad_old 2>/dev/null
-@rm -rf ./data
-@rm -rf ./_build


.PHONY: integration-test-all init-test-framework test-ibc-hooks test-tokenfactory clean-testing-data

###############################################################################
### Protobuf ###
###############################################################################
Expand Down
10 changes: 4 additions & 6 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

This project is meant to increase the success ratio for new core releases, improve reliability and features for [@terra-money/feather.js](https://github.com/terra-money/feather.js). This tests are written using TypeScript with [jest](https://jestjs.io/) and executed in parallel to improve time execution.


### Development

This set of tests must run out of the box in Linux-based systems installing [GoLang 1.20](https://go.dev/), [jq](https://stedolan.github.io/jq/), [screen](https://www.geeksforgeeks.org/screen-command-in-linux-with-examples/) and [rly](https://github.com/cosmos/relayer).

Keep in mind that tests are executed in paralel when using the same account with two different tests it can misslead test results with errors like "account missmatch sequence" when submitting two transactions with the same nonce, missmatching balances, etc...

Another good practice with this framework is to isolate and assert values within a test considering that the data is not wiped out each time a new test is executed.
Expand All @@ -18,15 +19,12 @@ Folders structure:
├── package-lock.json
├── README.md
└── src
├── setup # Scripts to start the two networks and relayers
├── contracts # WASM Contracts to be used in the tests.
│ └── reflect.wasm
├── helpers # Functions to improve code readability and avoid duplications.
│ ├── const.ts
│ ├── lcd.connection.ts
│ └── mnemonics.ts
└── modules # Tests splited by module that intent to test.
├── auth.test.ts
├── feeshare.test.ts
└── pob.test.ts
└── modules # Tests splited by module

```
2 changes: 1 addition & 1 deletion integration-tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ module.exports = {
testMatch: ['**/*.test.ts'],
verbose: true,
testTimeout: 30000,
maxConcurrency: 5,
maxConcurrency: 4,
};
7 changes: 6 additions & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"description": "Integration tests for Core using feather.js",
"main": "index.ts",
"scripts": {
"test": "jest"
"test:init" : "bash src/setup/init-test-framework.sh",
"test:relayer": "bash src/setup/relayer/init-relayer.sh",
"test:chain:upgrade" : "bash src/setup/chain-upgrade/chain-upgrade.sh",
"test:start" : "jest",
"start": "npm run test:init && npm run test:relayer && npm run test:start",
"test:clean": "rm -rf test-data chain-upgrade-data && pkill terrad && pkill terrad && pkill rly"
},
"repository": {
"type": "git",
Expand Down
57 changes: 26 additions & 31 deletions integration-tests/src/modules/alliance/alliance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,36 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/
// the same wallet on both chains and start
// an Alliance creation process
beforeAll(async () => {
try {
let blockHeight = (await LCD.chain1.tendermint.blockInfo("test-1")).block.header.height;
let tx = await chain1Wallet.createAndSignTx({
msgs: [new MsgTransfer(
"transfer",
"channel-0",
Coin.fromString("100000000uluna"),
allianceAccountAddress,
allianceAccountAddress,
new Height(2, parseInt(blockHeight) + 100),
undefined,
""
)],
chainID: "test-1",
});
let blockHeight = (await LCD.chain1.tendermint.blockInfo("test-1")).block.header.height;
let tx = await chain1Wallet.createAndSignTx({
msgs: [new MsgTransfer(
"transfer",
"channel-0",
Coin.fromString("100000000uluna"),
allianceAccountAddress,
allianceAccountAddress,
new Height(2, parseInt(blockHeight) + 100),
undefined,
""
)],
chainID: "test-1",
});

let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
await blockInclusion();
let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any;
expect(txResult).toBeDefined();
let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
await blockInclusion();
let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any;
expect(txResult).toBeDefined();

// Check during 5 blocks for the receival
// of the IBC coin on chain-2
for (let i = 0; i <= 5; i++) {
await blockInclusion();
let _ibcCoin = (await LCD.chain2.bank.balance(allianceAccountAddress))[0].find(c => c.denom.startsWith("ibc/"));
if (_ibcCoin) {
expect(_ibcCoin.denom.startsWith("ibc/")).toBeTruthy();
break;
}
// Check during 5 blocks for the receival
// of the IBC coin on chain-2
for (let i = 0; i <= 5; i++) {
await blockInclusion();
let _ibcCoin = (await LCD.chain2.bank.balance(allianceAccountAddress))[0].find(c => c.denom.startsWith("ibc/"));
if (_ibcCoin) {
expect(_ibcCoin.denom.startsWith("ibc/")).toBeTruthy();
break;
}
}
catch (e) {
expect(e).toBeUndefined();
}
});

test('Must contain the expected module params', async () => {
Expand Down
144 changes: 69 additions & 75 deletions integration-tests/src/modules/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,81 +62,75 @@ describe("Auth Module (https://github.com/terra-money/cosmos-sdk/tree/release/v0
});

test('Must create a random vesting account', async () => {
try {
const randomAccountAddress = new MnemonicKey().accAddress("terra");
// Register a new vesting account
let tx = await wallet.createAndSignTx({
msgs: [new MsgCreateVestingAccount(
vestAccAddr1,
randomAccountAddress,
Coins.fromString("100uluna"),
moment().add(1, "minute").unix(),
false,
)],
chainID: "test-1",
});
const randomAccountAddress = new MnemonicKey().accAddress("terra");
// Register a new vesting account
let tx = await wallet.createAndSignTx({
msgs: [new MsgCreateVestingAccount(
vestAccAddr1,
randomAccountAddress,
Coins.fromString("100uluna"),
moment().add(1, "minute").unix(),
false,
)],
chainID: "test-1",
});

let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
await blockInclusion();
let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1");
expect(JSON.parse(txResult.raw_log)[0].events)
.toEqual([{
"type": "message",
"attributes": [{
"key": "action",
"value": "/cosmos.vesting.v1beta1.MsgCreateVestingAccount"
}, {
"key": "sender",
"value": vestAccAddr1
}, {
"key": "module",
"value": "vesting"
}]
},
{
"type": "coin_spent",
"attributes": [{
"key": "spender",
"value": vestAccAddr1
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "coin_received",
"attributes": [{
"key": "receiver",
"value": randomAccountAddress
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "transfer",
"attributes": [{
"key": "recipient",
"value": randomAccountAddress
}, {
"key": "sender",
"value": vestAccAddr1
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "message",
"attributes": [{
"key": "sender",
"value": vestAccAddr1
}]
}
])
}
catch (e) {
expect(e).toBeUndefined();
}
let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
await blockInclusion();
let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any;
expect(txResult.logs[0].events)
.toEqual([{
"type": "message",
"attributes": [{
"key": "action",
"value": "/cosmos.vesting.v1beta1.MsgCreateVestingAccount"
}, {
"key": "sender",
"value": vestAccAddr1
}, {
"key": "module",
"value": "vesting"
}]
},
{
"type": "coin_spent",
"attributes": [{
"key": "spender",
"value": vestAccAddr1
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "coin_received",
"attributes": [{
"key": "receiver",
"value": randomAccountAddress
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "transfer",
"attributes": [{
"key": "recipient",
"value": randomAccountAddress
}, {
"key": "sender",
"value": vestAccAddr1
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "message",
"attributes": [{
"key": "sender",
"value": vestAccAddr1
}]
}])
});
});
Loading

0 comments on commit 19c0ccf

Please sign in to comment.