Skip to content

Commit

Permalink
fix(test): aens suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mradkov committed Jun 10, 2021
1 parent b5103e4 commit 0fe69eb
Showing 1 changed file with 194 additions and 31 deletions.
225 changes: 194 additions & 31 deletions test/cli/aens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

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

import { configure, plan, ready, execute as exec, WALLET_NAME, randomString, genAccount } from './index'
import { Crypto } from '@aeternity/aepp-sdk'
import { before, describe, it } from 'mocha'
import {
configure,
execute as exec,
genAccount,
plan,
randomString,
ready,
WALLET_NAME
} from './index'

plan(10000000000000)

Expand All @@ -31,21 +38,15 @@ function randomName (length, namespace = '.chain') {
describe('CLI AENS Module', function () {
configure(this)
const { publicKey } = Crypto.generateKeyPair()
let wallet
let nameAuctionsSupported
let name
let name2
let name3
let name4
let salt
let wallet, nameAuctionsSupported, name, name2, name3, name4, 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'
nameAuctionsSupported = +majorVersion === 6 && version !== '5.0.0-rc.1'
name = randomName(12, nameAuctionsSupported ? '.chain' : '.test')
name2 = randomName(13, nameAuctionsSupported ? '.chain' : '.test')
name3 = randomName(13, nameAuctionsSupported ? '.chain' : '.test')
Expand All @@ -56,15 +57,42 @@ describe('CLI AENS Module', function () {
})

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

updateTx.blockHeight.should.be.gt(0)
const isUpdated = !!updateTx.pointers.find(({ id }) => id === address)
isUpdated.should.be.equal(true)
})

it('Full claim with options', async () => {
const updateTx = JSON.parse(await execute(['name', 'full-claim', WALLET_NAME, '--password', 'test', name4, '--json', '--nameTtl', 50, '--nameFee', '3865700000000000000', '--clientTtl', 50]))
const updateTx = JSON.parse(
await execute([
'name',
'full-claim',
WALLET_NAME,
'--password',
'test',
name4,
'--json',
'--nameTtl',
50,
'--nameFee',
'3865700000000000000',
'--clientTtl',
50
])
)
const address = await wallet.address()

updateTx.blockHeight.should.be.gt(0)
Expand All @@ -75,7 +103,17 @@ describe('CLI AENS Module', function () {
})

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

Expand All @@ -87,81 +125,206 @@ describe('CLI AENS Module', function () {
})

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

claim.blockHeight.should.be.gt(0)
claim.pointers.length.should.be.equal(0)
nameResult.status.should.equal('CLAIMED')
})

it('Update Name', async () => {
const updateTx = JSON.parse(await execute(['name', 'update', WALLET_NAME, name2, publicKey, '--password', 'test', '--json']))
const updateTx = JSON.parse(
await execute([
'name',
'update',
WALLET_NAME,
name2,
publicKey,
'--password',
'test',
'--json'
])
)
const nameResult = JSON.parse(await exec(['inspect', name2, '--json']))

updateTx.blockHeight.should.be.gt(0)
const isUpdatedNode = !!nameResult.pointers.find(({ id }) => id === publicKey)
const isUpdatedNode = !!nameResult.pointers.find(
({ id }) => id === publicKey
)
isUpdatedNode.should.be.equal(true)
nameResult.status.should.equal('CLAIMED')
})

it('extend name ttl', async () => {
const height = await wallet.height()
const extendTx = JSON.parse(await execute(['name', 'extend', WALLET_NAME, name2, 50, '--password', 'test', '--json']))
const extendTx = JSON.parse(
await execute([
'name',
'extend',
WALLET_NAME,
name2,
50,
'--password',
'test',
'--json'
])
)

const nameResult = JSON.parse(await exec(['inspect', name2, '--json']))
const isExtended = (nameResult.ttl - 50) >= height
const isExtended = nameResult.ttl - 50 >= height
isExtended.should.be.equal(true)
extendTx.blockHeight.should.be.gt(0)
nameResult.status.should.equal('CLAIMED')
})

it('Fail spend by name on invalid input', async () => {
const amount = 100000009
await execute(['account', 'spend', WALLET_NAME, '--password', 'test', 'sdasdaasdas', amount, '--json'])
.should.be.rejectedWith('Invalid name or address')
await execute([
'account',
'spend',
WALLET_NAME,
'--password',
'test',
'sdasdaasdas',
amount,
'--json'
]).should.be.rejectedWith('Invalid name or address')
})

it('Spend by name', async () => {
const amount = 100000009
const spendTx = JSON.parse(await execute(['account', 'spend', WALLET_NAME, '--password', 'test', name2, amount, '--json']))
const spendTx = JSON.parse(
await execute([
'account',
'spend',
WALLET_NAME,
'--password',
'test',
name2,
amount,
'--json'
])
)

const nameObject = await wallet.aensQuery(name2)
spendTx.tx.tx.recipientId.should.be.equal(nameObject.id)
const balance = await wallet.getBalance(publicKey)
balance.should.be.equal(`${amount}`)
})

it('Transfer name', async () => {
const account = genAccount()
await wallet.addAccount(account)

const transferTx = JSON.parse(await execute(['name', 'transfer', WALLET_NAME, name2, await account.address(), '--password', 'test', '--json']))
const transferTx = JSON.parse(
await execute([
'name',
'transfer',
WALLET_NAME,
name2,
await account.address(),
'--password',
'test',
'--json'
])
)

transferTx.blockHeight.should.be.gt(0)
await wallet.spend(1, await account.address(), { denomination: 'ae' })
const claim2 = await wallet.aensQuery(name2)
const transferBack = await claim2.transfer(await wallet.address(), { onAccount: await account.address() })
const transferBack = await claim2.transfer(await wallet.address(), {
onAccount: await account.address()
})
transferBack.blockHeight.should.be.gt(0)
})

it('Revoke Name', async () => {
const revoke = JSON.parse(await execute(['name', 'revoke', WALLET_NAME, '--password', 'test', name2, '--json']))
const revoke = JSON.parse(
await execute([
'name',
'revoke',
WALLET_NAME,
'--password',
'test',
name2,
'--json'
])
)

const nameResult = JSON.parse(await exec(['inspect', name2, '--json']))

revoke.blockHeight.should.be.gt(0)
nameResult.status.should.equal('AVAILABLE')
})

describe('Name Auction', () => {
const nameFee = '3665700000000000000'

it('Open auction', async () => {
const account = genAccount()
await wallet.addAccount(account)
await wallet.spend('30000000000000000000000', await account.address())
const preclaim = await wallet.aensPreclaim(name, { onAccount: await account.address() })
const claim = await preclaim.claim({ onAccount: await account.address() })
const preclaim = await wallet.aensPreclaim(name, {
onAccount: await account.address()
})
const claim = await preclaim.claim({
onAccount: await account.address()
})
claim.blockHeight.should.be.gt(0)
})

it('Make bid', async () => {
const bid = JSON.parse(await execute(['name', 'bid', WALLET_NAME, '--password', 'test', name, nameFee, '--json']))
const bid = JSON.parse(
await execute([
'name',
'bid',
WALLET_NAME,
'--password',
'test',
name,
nameFee,
'--json'
])
)

bid.tx.nameSalt.should.be.equal(0)
bid.tx.nameFee.should.be.equal(nameFee)
})

it('Fail on open again', async () => {
const preClaim = JSON.parse(await execute(['name', 'pre-claim', WALLET_NAME, '--password', 'test', name, '--json']))
await execute(['name', 'claim', WALLET_NAME, '--password', 'test', name, preClaim.salt, '--json'])
.should.be.rejectedWith('Giving up after 10 blocks mined')
const preClaim = JSON.parse(
await execute([
'name',
'pre-claim',
WALLET_NAME,
'--password',
'test',
name,
'--json'
])
)
await execute([
'name',
'claim',
WALLET_NAME,
'--password',
'test',
name,
preClaim.salt,
'--json'
]).should.be.rejectedWith('Giving up after 10 blocks mined')
})
})
})

0 comments on commit 0fe69eb

Please sign in to comment.