Skip to content

Commit

Permalink
fix(): Fix test for AENS
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak committed Oct 11, 2019
1 parent a5eb23a commit fae6ce8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 44 deletions.
2 changes: 2 additions & 0 deletions bin/aecli-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ program
.option('--ttl [ttl]', 'Override the ttl that the transaction is going to be sent with', utils.constant.TX_TTL)
.option('--fee [fee]', 'Override the fee that the transaction is going to be sent with')
.option('--nonce [nonce]', 'Override the nonce that the transaction is going to be sent with')
.option('-P, --password [password]', 'Wallet Password')
.option('--networkId [networkId]', 'Network id (default: ae_mainnet)')
.option('-f --force', 'Ignore node version compatibility check')
.option('--json', 'Print result in json format', utils.constant.OUTPUT_JSON)

Expand Down
7 changes: 4 additions & 3 deletions bin/commands/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ async function fullClaim (walletPath, domain, options) {
try {
// Validate `name`
validateName(domain)
if (domain.length - 4 < 13) throw new Error('Full name claiming works only with name longer then 12 symbol(Not trigger auction)')
const [_, namespace] = domain.split('.')
if (namespace !== 'test' && domain.length - 4 < 13) throw new Error('Full name claiming works only with name longer then 12 symbol(Not trigger auction)')

// Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client with this `keyPair`
const client = await initClientByWalletFile(walletPath, options)
Expand Down Expand Up @@ -292,11 +293,11 @@ async function lookUp (domain, options) {
await updateNameStatus(domain)(client),
json
)
process.exit(0)
exit(0)
})
} catch (e) {
printError(e.message)
process.exit(0)
exit(0)
}
}

Expand Down
36 changes: 19 additions & 17 deletions bin/commands/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

import { initChain } from '../utils/cli'
import { exit, initChain } from '../utils/cli'
import { handleApiError } from '../utils/errors'
import { printBlock, print, printError, printUnderscored, printTransaction, printValidation } from '../utils/print'
import { getBlock } from '../utils/helpers'
Expand All @@ -36,7 +36,7 @@ async function version (options) {
const { consensusProtocolVersion } = client.getNodeInfo()
if (json) {
print(status)
process.exit(0)
exit()
}
const FORKS = {
3: 'Fortuna',
Expand All @@ -53,10 +53,11 @@ async function version (options) {
printUnderscored('Pending transactions count', status.pendingTransactionsCount)
printUnderscored('Solutions', status.solutions)
printUnderscored('Syncing', status.syncing)
exit()
})
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

Expand All @@ -69,15 +70,12 @@ async function getNetworkId (options) {
// Call `getStatus` API and print it
await handleApiError(async () => {
const { networkId } = await client.api.getStatus()
if (json) {
print({ networkId })
process.exit(0)
}
printUnderscored('Network ID', networkId)
json ? print({ networkId }) : printUnderscored('Network ID', networkId)
exit(0)
})
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

Expand All @@ -92,14 +90,15 @@ async function ttl (absoluteTtl, options) {
const height = await client.height()
if (json) {
print({ absoluteTtl, relativeTtl: +height + +absoluteTtl })
process.exit(0)
} else {
printUnderscored('Absolute TTL', absoluteTtl)
printUnderscored('Relative TTL', +height + +absoluteTtl)
}
printUnderscored('Absolute TTL', absoluteTtl)
printUnderscored('Relative TTL', +height + +absoluteTtl)
exit()
})
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

Expand All @@ -115,7 +114,7 @@ async function top (options) {
)
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

Expand All @@ -133,7 +132,7 @@ async function play (options) {

if (height && height > parseInt(top.height)) {
printError('Height is bigger then height of top block')
process.exit(1)
exit(1)
}

printBlock(top, json)
Expand All @@ -142,10 +141,11 @@ async function play (options) {
height
? await playWithHeight(height, top.prevHash)(client, json)
: await playWithLimit(--limit, top.prevHash)(client, json)
exit()
})
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

Expand Down Expand Up @@ -190,11 +190,13 @@ async function broadcast (signedTx, options) {
} catch (e) {
if (!!verify && e.errorData) printValidation(e.errorData)
if (!verify) printValidation(await e.verifyTx())
} finally {
exit()
}
})
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

Expand Down
81 changes: 57 additions & 24 deletions test/cli/aens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,92 @@

import { before, describe, it } from 'mocha'

import { configure, plan, ready, execute as exec, parseBlock, WALLET_NAME } from './index'
import { configure, plan, ready, execute as exec, WALLET_NAME } from './index'
import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'

plan(1000000000)
plan(10000000000000)

const execute = (arg) => exec(arg, { withNetworkId: true })
function randomName () {
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(36) + '.test'

function randomName (length, namespace = '.aet') {
return randomString(length).toLowerCase() + namespace
}

function randomString (len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let randomString = ''
for (let i = 0; i < len; i++) {
const randomPoz = Math.floor(Math.random() * charSet.length)
randomString += charSet.substring(randomPoz, randomPoz + 1)
}
return randomString
}

describe.skip('CLI AENS Module', function () {
describe('CLI AENS Module', function () {
configure(this)
const name = randomName()
let wallet
let nameAuctionsSupported
let name2
let salt

before(async function () {
// Spend tokens for wallet
try {
wallet = await ready(this)
const { version } = wallet.getNodeInfo()
const [majorVersion] = version.split('.')
nameAuctionsSupported = +majorVersion === 5 && version !== '5.0.0-rc.1'
name2 = randomName(13, nameAuctionsSupported ? '.aet' : '.test')
} catch (e) {
console.log(e.toString())
}
})

it('Claim Name', async () => {
await execute(['name', 'claim', WALLET_NAME, '--password', 'test', name])
it('Full claim', async () => {
const name = randomName(13)
const updateTx = JSON.parse(await execute(['name', 'full-claim', WALLET_NAME, '--password', 'test', name, '--json']))
const address = await wallet.address()

const nameResult = parseBlock(await execute(['inspect', name]))
const isHash = nameResult.name_hash !== 'N/A'
updateTx.blockHeight.should.be.gt(0)
const isUpdated = !!updateTx.pointers.find(({ id }) => id === address)
isUpdated.should.be.equal(true)
})

it('Pre Claim Name', async () => {
const preClaim = JSON.parse(await execute(['name', 'pre-claim', WALLET_NAME, '--password', 'test', name2, '--json']))
const nameResult = JSON.parse(await execute(['inspect', name2, '--json']))
salt = preClaim.salt

preClaim.blockHeight.should.be.gt(0)
preClaim.salt.should.be.a('number')
preClaim.commitmentId.indexOf('cm').should.not.be.equal(-1)
nameResult.name.should.be.equal(name2)
nameResult.status.should.equal('AVAILABLE')
})

it('Claim Name', async () => {
const claim = JSON.parse(await execute(['name', 'claim', WALLET_NAME, '--password', 'test', name2, salt, '--json']))
const nameResult = JSON.parse(await execute(['inspect', name2, '--json']))

claim.blockHeight.should.be.gt(0)
claim.pointers.length.should.be.equal(0)
nameResult.status.should.equal('CLAIMED')
isHash.should.equal(true)
})
it('Update Name', async () => {
const { publicKey } = generateKeyPair()
await execute(['name', 'update', WALLET_NAME, '--password', 'test', name, publicKey])

const nameResult = parseBlock(await execute(['inspect', name]))
const isHaveUpdatedPointer = !!(JSON.parse(nameResult.pointers).find(p => p.id === publicKey))
const updateTx = JSON.parse(await execute(['name', 'update', WALLET_NAME, '--password', 'test', name2, publicKey, '--json']))
const nameResult = JSON.parse(await execute(['inspect', name2, '--json']))

updateTx.blockHeight.should.be.gt(0)
const isUpdatedNode = !!nameResult.pointers.find(({ id }) => id === publicKey)
isUpdatedNode.should.be.equal(true)
nameResult.status.should.equal('CLAIMED')
isHaveUpdatedPointer.should.equal(true)
})
it('Revoke Name', async () => {
let nameResult = parseBlock(await execute(['inspect', name]))
nameResult.status.should.equal('CLAIMED')

await execute(['name', 'revoke', WALLET_NAME, '--password', 'test', name])

nameResult = parseBlock(await execute(['inspect', name]))
const revoke = JSON.parse(await execute(['name', 'revoke', WALLET_NAME, '--password', 'test', name2, '--json']))
const nameResult = JSON.parse(await execute(['inspect', name2, '--json']))

revoke.blockHeight.should.be.gt(0)
nameResult.status.should.equal('AVAILABLE')
nameResult.name_hash.should.equal('N/A')
nameResult.pointers.should.equal('N/A')
})
})

0 comments on commit fae6ce8

Please sign in to comment.