Skip to content

Script Usage Examples

Benjamin Smith edited this page Feb 23, 2019 · 9 revisions

Most, if not all of these commands will require one to run Environment Setup (which registers accounts and tokens on the contract and funds each of the accounts for all the tokens)

truffle migrate
npm run setup

Claim Withdraw

The following example demonstrates usage of many different scripts. Although here they are run with npx truffle exec they are also part of the node package and can be run with npm run.

IN order to claim withdraws, you will need to ensure the database is correctly synchronized to match the following scenario

A quick way to "prepare" you database is as follows in a python shell

from pymongo import MongoClient
client = MongoClient()
db = client.test_db
collection = db.withdraws

new_posts = [
    {
        "accountId": 1,
        "tokenId": 1,
        "amount": 1,
        "slot": 1,
        "slotIndex": 0,
        "valid": True
    },
    {
        "accountId": 2,
        "tokenId": 1,
        "amount": 1,
        "slot": 1,
        "slotIndex": 1,
        "valid": False
    },
    {
        "accountId": 3,
        "tokenId": 2,
        "amount": 1,
        "slot": 1,
        "slotIndex": 2,
        "valid": True
    }
]

result = posts.insert_many(new_posts)
npx truffle exec scripts/deposit.js  1 1 1
npx truffle exec scripts/deposit.js  1 2 1
npx truffle exec scripts/mine_blocks.js  20
npx truffle exec scripts/apply_deposits.js  0 0x0
npx truffle exec scripts/apply_deposits.js  1 0x0
npx truffle exec scripts/request_withdraw.js  1 1 1
npx truffle exec scripts/request_withdraw.js  2 1 1
npx truffle exec scripts/request_withdraw.js  1 3 1
npx truffle exec scripts/mine_blocks.js  20
npx truffle exec scripts/apply_withdrawals.js  0 0x0 0x0
npx truffle exec scripts/apply_withdrawals.js  1 0x4c90e21c23e2888ed383b709a30b1249f44f8540a8acf3679d821a1a3f16fbfd 0x0
# [Generic Claims]
npx truffle exec scripts/claim_withdraw.js 1 1 1
npx truffle exec scripts/claim_withdraw.js 1 3 2
# [Invalid: Will fail]
npx truffle exec scripts/claim_withdraw.js 1 1 2
# [Double Claim: Will fail]
npx truffle exec scripts/claim_withdraw.js 1 1 1
Clone this wiki locally