Skip to content

Commit

Permalink
feat: add dnsAllocCost method to MNS contract and corresponding tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey authored Jan 10, 2025
1 parent 4701a9a commit 2f83f00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/contracts-wrappers/mns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Args, bytesToStr, strToBytes, U256 } from '../basicElements'
import { Args, bytesToStr, strToBytes, U256, U64 } from '../basicElements'
import { Operation } from '../operation'
import { Provider, PublicProvider } from '../provider'
import { CallSCOptions, ReadSCOptions, SmartContract } from '../smartContracts'
Expand Down Expand Up @@ -151,4 +151,16 @@ export class MNS extends SmartContract {
)
return domainsBytes.map((d) => bytesToStr(d))
}

async dnsAllocCost(domain: string, options?: ReadSCOptions): Promise<bigint> {
const res = await this.read(
'dnsAllocCost',
new Args().addString(domain),
options
)

if (res.info.error) throw new Error(res.info.error)

return U64.fromBytes(res.value)
}
}
11 changes: 11 additions & 0 deletions test/integration/mns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,15 @@ describe('MNS tests using PublicProvider', () => {

await expect(mns.free(domain)).rejects.toThrow()
}, 300000)

test('get dns allocation cost', async () => {
const domain = 'trloloooooooooooooooololololzs'
const res = await mns.dnsAllocCost(domain)
expect(res).toBeGreaterThan(0n)
})

test('get dns allocation cost fail if invalid domain', async () => {
const domain = 'trloloooooooooooooooololoPolzs////'
await expect(mns.dnsAllocCost(domain)).rejects.toThrow(/.*Invalid domain.*/)
})
})

1 comment on commit 2f83f00

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for experimental massa-web3

St.
Category Percentage Covered / Total
🟡 Statements 66.49% 1254/1886
🔴 Branches 43.6% 201/461
🔴 Functions 46.93% 222/473
🟡 Lines 67.08% 1247/1859

Test suite run success

134 tests passing in 15 suites.

Report generated by 🧪jest coverage report action from 2f83f00

Please sign in to comment.