Skip to content

Commit

Permalink
feat(AENS): Add test for auction
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak committed Oct 11, 2019
1 parent fae6ce8 commit 9f4f6b2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
10 changes: 8 additions & 2 deletions bin/commands/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async function nameBid (walletPath, domain, nameFee, options) {
}

async function fullClaim (walletPath, domain, options) {
const { ttl, fee, nonce, nameFee, json, nameTtl, clientTtl } = options
let { ttl, fee, nonce, nameFee, json, nameTtl, clientTtl } = options
try {
// Validate `name`
validateName(domain)
Expand All @@ -264,9 +264,15 @@ async function fullClaim (walletPath, domain, options) {
}

// Wait for next block and create `claimName` transaction
const preclaim = await client.aensPreclaim(domain, nameFee, { nonce, ttl, fee })
if (nonce) {
nonce = parseInt(nonce)
}
const preclaim = await client.aensPreclaim(domain, { nonce, ttl, fee })
nonce += 1
const claim = await preclaim.claim({ nonce, ttl, fee, nameFee })
nonce += 1
const updateTx = await claim.update(await client.address(), { nonce, ttl, fee, nameTtl, clientTtl })
nonce += 1

printTransaction(
updateTx,
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"aecli": "./bin/aecli.js"
},
"dependencies": {
"@aeternity/aepp-sdk": "^5.0.0",
"@aeternity/aepp-sdk": "https://github.com/aeternity/aepp-sdk-js.git#develop",
"child_process": "^1.0.2",
"commander": "^2.19.0",
"esm": "^3.0.84",
Expand Down
35 changes: 35 additions & 0 deletions test/cli/aens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { before, describe, it } from 'mocha'

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

plan(10000000000000)

Expand All @@ -42,6 +43,7 @@ describe('CLI AENS Module', function () {
configure(this)
let wallet
let nameAuctionsSupported
let name
let name2
let salt

Expand All @@ -52,6 +54,7 @@ describe('CLI AENS Module', function () {
const { version } = wallet.getNodeInfo()
const [majorVersion] = version.split('.')
nameAuctionsSupported = +majorVersion === 5 && version !== '5.0.0-rc.1'
name = randomName(12, nameAuctionsSupported ? '.aet' : '.test')
name2 = randomName(13, nameAuctionsSupported ? '.aet' : '.test')
} catch (e) {
console.log(e.toString())
Expand All @@ -67,6 +70,17 @@ describe('CLI AENS Module', function () {
const isUpdated = !!updateTx.pointers.find(({ id }) => id === address)
isUpdated.should.be.equal(true)
})
it('Full claim with options', async () => {
const name = randomName(13)
const updateTx = JSON.parse(await execute(['name', 'full-claim', WALLET_NAME, '--password', 'test', name, '--json', '--nameTtl', 50, '--nameFee', '3865700000000000000', '--clientTtl', 50]))
const address = await wallet.address()

updateTx.blockHeight.should.be.gt(0)
updateTx.tx.nameTtl.should.be.equal(50)
updateTx.tx.clientTtl.should.be.equal(50)
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']))
Expand Down Expand Up @@ -105,4 +119,25 @@ describe('CLI AENS Module', function () {
revoke.blockHeight.should.be.gt(0)
nameResult.status.should.equal('AVAILABLE')
})
describe('Name Auction', () => {
const nameFee = '3665700000000000000'
it('Open auction', async () => {
const account = MemoryAccount({ keypair: generateKeyPair() })
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() })
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']))
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']))
const claim = await execute(['name', 'claim', WALLET_NAME, '--password', 'test', name, preClaim.salt, '--json'])
claim.indexOf('Giving up after 10 blocks mined').should.not.be.equal(-1)
})
})
})

0 comments on commit 9f4f6b2

Please sign in to comment.