Skip to content

Testing user deployer whitelist APIs #277

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
19410c1
Get/Modify Tier Info support in loom-js.
suhasagg Jun 1, 2019
7944761
whitelisting fee validation.
suhasagg Jun 7, 2019
2b46201
Fix error message.
suhasagg Jun 7, 2019
8ad6733
Review changes taken into Account
suhasagg Jun 7, 2019
4981610
Take fee as BigUInt in ModifyTierInfoRequest
suhasagg Jun 7, 2019
ce32c7d
TierID fix
suhasagg Jun 7, 2019
60d6a2e
Add RemoveUserDeployer in user-deployer-whitelist
suhasagg Jun 7, 2019
0c5fae2
Review changes done.
suhasagg Jun 12, 2019
68aca81
Nomenclature fixed
suhasagg Jun 12, 2019
df39596
Fix error message
suhasagg Jun 12, 2019
d8c0431
Make fee, tierName optional in setTierInfo
suhasagg Jun 13, 2019
e7bba4f
User ITier object in setTierInfo
suhasagg Jun 13, 2019
6375f0f
User Deployer Whitelist Client
suhasagg Jun 13, 2019
477fabb
Merge branch 'master' into TestingUserDeployerWhitelistAPIs
suhasagg Jun 13, 2019
ddfd7f0
Add e2e tests for user-deplouer-whitelist
suhasagg Jun 14, 2019
502f5f1
Merge branch 'TestingUserDeployerWhitelistAPIs' of github.com:loomnet…
suhasagg Jun 14, 2019
8aeb9c2
Add genesis for user-deployer-whitelist
suhasagg Jun 14, 2019
cfa0c14
Add loom.yml for user-deployer-whitelist
suhasagg Jun 14, 2019
fd1550d
Shell script for user-deployer-whitelist e2e tests
suhasagg Jun 14, 2019
b6239ab
Update e2e_user_deployer_whitelist_test.sh
suhasagg Jun 14, 2019
42fa88e
Delete user_deployer_whitlelist_client.js
suhasagg Jun 14, 2019
3fcd25d
Formatting fix
suhasagg Jun 14, 2019
5e17d96
Merge branch 'TestingUserDeployerWhitelistAPIs' of github.com:loomnet…
suhasagg Jun 14, 2019
c2e6df2
e2e tests integration for user-deployer-whitelist
suhasagg Jun 14, 2019
58db998
user-deployer-whitelist tests integration
suhasagg Jun 14, 2019
1d01aa8
Support for running tests on local
suhasagg Jun 14, 2019
827ac27
Map user-deployer-whitelist tests command
suhasagg Jun 14, 2019
5108d03
Tests for user-deployer-whitelist
suhasagg Jun 14, 2019
a49266f
Initialise balance of user so that whitelisting fee can be deducted.
suhasagg Jun 14, 2019
1b6d617
Approve user-deployer-whitelist contract as spender - coin contract call
suhasagg Jun 14, 2019
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
2 changes: 2 additions & 0 deletions .travis_e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eval "$(GIMME_GO_VERSION=1.10.2 gimme)"

export BUILD_ID=build-1046

bash e2e_user_deployer_whitelist_test.sh

bash e2e_tests.sh

if [ "${PLASMA_TEST:-}" ]; then
Expand Down
114 changes: 114 additions & 0 deletions e2e_support/user-deployer-whitelist/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"contracts": [
{
"vm": "plugin",
"format": "plugin",
"name": "coin",
"location": "coin:1.0.0",
"init": {
"accounts": [
{
"owner": {
"chain_id": "default",
"local": "dHVZ95Bqnn3dsget6tyq72cJS3E="
},
"balance": 10000
}
]
}
},
{
"vm": "plugin",
"format": "plugin",
"name": "dposV2",
"location": "dposV2:2.0.0",
"init": {
"params": {
"validatorCount": "21",
"electionCycleLength": "604800"
},
"validators": [
{
"pubKey": "XvkW4a0U6o8x/SYtDx5RFTWcATdf9212+OodZWFR0mc=",
"power": "10"
},
{
"pubKey": "YOVrdKhgPrRp0oy2NCHkJv0MQBdVWbbsnwH2FUkOPng=",
"power": "10"
}
]
}
},
{
"vm": "plugin",
"format": "plugin",
"name": "chainconfig",
"location": "chainconfig:1.0.0",
"init": {
"owner": {
"chainId": "default",
"local": "S7Mg3vyaNSnqchAyvZWoYF7S1UM="
},
"params": {
"voteThreshold":"100",
"numBlockConfirmations":"1"
},
"features": [
{
"name":"mw:deploy-wl",
"status":"WAITING",
"autoEnable": true
},
{
"name":"mw:userdeploy-wl",
"status":"WAITING",
"autoEnable": true
}
]
}
},
{
"vm": "plugin",
"format": "plugin",
"name": "deployerwhitelist",
"location": "deployerwhitelist:1.0.0",
"init": {
"owner": {
"chainId": "default",
"local": "S7Mg3vyaNSnqchAyvZWoYF7S1UM="
},
"deployers": [
{
"address": {
"chainId":"default",
"local":"duzR9yYfz0xoTil74+3wO4JeAcQ="
},
"flags": 2
}
]
}
},
{
"vm": "plugin",
"format": "plugin",
"name": "user-deployer-whitelist",
"location": "user-deployer-whitelist:1.0.0",
"init": {
"owner": {
"chainId": "default",
"local": "S7Mg3vyaNSnqchAyvZWoYF7S1UM="
},
"tier_info": [
{
"id": 0,
"fee": "10",
"name": "tier1"
}
]
}

}

]
}

16 changes: 16 additions & 0 deletions e2e_support/user-deployer-whitelist/loom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ChainID: "default"
RegistryVersion: 2
ReceiptsVersion: 2
DPOSVersion: 2
DeployerWhitelist:
ContractEnabled: true
ChainConfig:
ContractEnabled: true
UserDeployerWhitelist:
ContractEnabled: true
ContractLogLevel: "debug"
LoomLogLevel: "debug"
BootLegacyDPoS: true
GoContractDeployerWhitelist:
Enabled: true
DeployEnabled: true
101 changes: 101 additions & 0 deletions e2e_user_deployer_whitelist_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# To run this script with a locally built loom binary set the LOOM_BIN env var to point to your loom
# binary.

set -euxo pipefail

# Prepare env
DEFAULT_GOPATH=$GOPATH
REPO_ROOT=`pwd`
LOOM_DIR=`pwd`/tmp/e2e
LOOM_BIN=`pwd`/loom

# Check available platforms
PLATFORM='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
PLATFORM='linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
PLATFORM='osx'
else
echo "Platform not supported on this script yet"
exit -1
fi

download_dappchain() {
cd $LOOM_DIR
wget https://private.delegatecall.com/loom/linux/latest/loom
chmod +x loom
LOOM_BIN=`pwd`/loom
}

setup_dappchain() {
cd $LOOM_DIR
$LOOM_BIN init -f
cp -R $REPO_ROOT/e2e_support/* .
cp -R $REPO_ROOT/e2e_support/tm-config/* chaindata/config/
mkdir -p contracts
}

init_dappchain() {
cd $LOOM_DIR
rm -rf app.db
rm -rf chaindata
cp $REPO_ROOT/e2e_support/user-deployer-whitelist/loom.yml loom.yml
$LOOM_BIN init -f
cp $REPO_ROOT/e2e_support/user-deployer-whitelist/genesis.json genesis.json
echo 'Loom DAppChain initialized in ' $LOOM_DIR
}

start_chains() {
cd $LOOM_DIR
$LOOM_BIN run &
LOOM_PID=$!
sleep 5
}

stop_chains() {
if [[ -n "$LOOM_PID" ]]; then
kill -9 $LOOM_PID
LOOM_PID=""
fi
}

run_tests() {
yarn test:node
yarn test:browser
yarn e2e:node
}

cleanup() {
stop_chains
export GOPATH=$DEFAULT_GOPATH
}

if [ "${TRAVIS:-}" ]; then
mkdir -p $LOOM_DIR
fi

#download_dappchain

setup_dappchain

init_dappchain

trap cleanup EXIT

start_chains
cd $LOOM_DIR

yarn e2e:user-deployer-whitelist

stop_chains

cleanup

sleep 1

if [ "${TRAVIS:-}" ]; then
rm -rf $LOOM_DIR
fi
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"e2e:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.e2e.test.config.js | tap-spec",
"e2e:plasma-cash:honest": "yarn proto && yarn abi && yarn copy-contracts && tsc && yarn tape && tape -r dotenv/config dotenv_config_path=./.env.test dist/tests/e2e/plasma-cash/test-honest-operator.js | tap-spec",
"e2e:plasma-cash:hostile": "yarn proto && yarn abi && yarn copy-contracts && tsc && yarn tape && tape -r dotenv/config dotenv_config_path=./.env.test dist/tests/e2e/plasma-cash/test-hostile-operator.js | tap-spec",
"e2e:user-deployer-whitelist": "yarn proto && yarn abi && yarn copy-contracts && tsc && yarn tape && tape -r dotenv/config dotenv_config_path=./.env.test dist/tests/e2e/user-deployer-whitelist-tests.js | tap-spec",
"proto": "node ./scripts/gen-proto.js",
"abi": "node ./scripts/abi.js && bash ./scripts/fix_types.sh",
"copy-contracts": "node ./scripts/copy-contracts.js",
Expand Down
132 changes: 132 additions & 0 deletions src/tests/e2e/user-deployer-whitelist-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import test from 'tape'
import BN from 'bn.js'
import {
Address,
Contracts,
CryptoUtils,
createDefaultTxMiddleware,
Client,
LocalAddress
} from '../../index'
import { createTestHttpClient, waitForMillisecondsAsync } from '../helpers'
import { B64ToUint8Array } from '../../crypto-utils'

const toCoinE18 = (amount: number): BN => {
return new BN(10).pow(new BN(18)).mul(new BN(amount))
}

async function getClientAndContractCoin(
createClient: () => Client
): Promise<{
acct1Client: Client
acct1Coin: Contracts.Coin
acct1PubKey: Uint8Array
}> {
const acct1PrivKey = B64ToUint8Array(
'Hz9P3aHH62mO75A6uMVW3mn0U1KkZSq3t03jfOZfyZxjyJoJctNDY6awaVqOpjCGTjHZZxkc23Z3l39EjLOIFQ=='
)

const acct1PubKey = CryptoUtils.publicKeyFromPrivateKey(acct1PrivKey)
const acct1Client = createClient()

acct1Client.txMiddleware = createDefaultTxMiddleware(acct1Client, acct1PrivKey)

const acct1Coin = await Contracts.Coin.createAsync(
acct1Client,
new Address(acct1Client.chainId, LocalAddress.fromPublicKey(acct1PubKey))
)

return { acct1Client, acct1Coin, acct1PubKey, }
}

async function testBalanceOf(t: test.Test, createClient: () => Client) {
const { acct1Client, acct1Coin, acct1PubKey, } = await getClientAndContractCoin(createClient)

const acct1Owner = new Address(acct1Client.chainId, LocalAddress.fromPublicKey(acct1PubKey))
const acct1Balance = await acct1Coin.getBalanceOfAsync(acct1Owner)
t.assert(acct1Balance.eq(toCoinE18(10000)), 'Acct 1 balance should be 10000e18')
acct1Client.disconnect()

}

async function testApprove(t: test.Test, createClient: () => Client) {
const { acct1Client, acct1Coin, acct1PubKey } = await getClientAndContractCoin(createClient)

const contractAddr = await acct1Client.getContractAddressAsync('user-deployer-whitelist')
console.log("Contract Address", contractAddr)
await acct1Coin.approveAsync(contractAddr!, toCoinE18(10000))

acct1Client.disconnect()
}


async function getClientAndContract(
createClient: () => Client
): Promise<{
client: Client
userdeployerwhitelist: Contracts.UserDeployerWhitelist
pubKey: Uint8Array
deployerAddress: Address
}> {
const privKey = B64ToUint8Array(
'Hz9P3aHH62mO75A6uMVW3mn0U1KkZSq3t03jfOZfyZxjyJoJctNDY6awaVqOpjCGTjHZZxkc23Z3l39EjLOIFQ=='
)
const pubKey = CryptoUtils.publicKeyFromPrivateKey(privKey)
const client = createClient()
client.txMiddleware = createDefaultTxMiddleware(client, privKey)

const userdeployerwhitelist = await Contracts.UserDeployerWhitelist.createAsync(
client,
new Address(client.chainId, LocalAddress.fromPublicKey(pubKey))
)

const privKeyDeployer = B64ToUint8Array(
'ZGTsP8LUJkEWiqEZq3hqOKfCHCeV+CbYgbZK2/y53aDAaCJPBla4uLTsEtzm/Dczk8Ml8TL5+rAwKNfbuRZihg=='
)
const pubKeyDeployer = CryptoUtils.publicKeyFromPrivateKey(privKey)

const deployerAddress = new Address(client.chainId, LocalAddress.fromPublicKey(pubKeyDeployer))

return { client, userdeployerwhitelist, pubKey, deployerAddress }
}


async function addUserDeployer(t: test.Test, createClient: () => Client) {
const { client, userdeployerwhitelist, pubKey, deployerAddress } = await getClientAndContract(createClient)
await userdeployerwhitelist.addDeployerAsync(deployerAddress, 0)
client.disconnect()
}

async function getUserDeployer(t: test.Test, createClient: () => Client) {
const { client, userdeployerwhitelist, pubKey } = await getClientAndContract(createClient)
await userdeployerwhitelist.getDeployersAsync(new Address(client.chainId, LocalAddress.fromPublicKey(pubKey)))

client.disconnect()
}

async function getTierInfo(t: test.Test, createClient: () => Client) {
const { client, userdeployerwhitelist, pubKey } = await getClientAndContract(createClient)

await userdeployerwhitelist.getTierInfoAsync(0)

client.disconnect()
}

test('user-deployer-whitelist', async t => {
try {
await testBalanceOf(t, createTestHttpClient)
await waitForMillisecondsAsync(1000)
await testApprove(t, createTestHttpClient)
await waitForMillisecondsAsync(1000)
await addUserDeployer(t, createTestHttpClient)
await waitForMillisecondsAsync(1000)
await getUserDeployer(t, createTestHttpClient)
await waitForMillisecondsAsync(1000)
await getTierInfo(t, createTestHttpClient)
await waitForMillisecondsAsync(1000)

} catch (err) {
t.fail(err)
}
t.end()
})
2 changes: 2 additions & 0 deletions src/tests/e2e_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import './e2e/multiple-events-nd-tests'
// Contracts
import './e2e/coin-tests'
import './e2e/address-mapper-tests'
import './e2e/user-deployer-whitelist-tests'

// TODO: Re-enable once this is updated to DPOSv2
//import './e2e/dpos-tests'

Expand Down