Skip to content

Commit

Permalink
Merge pull request #21 from ensdomains/add-signer-to-write-transactions
Browse files Browse the repository at this point in the history
Add signer option to all write transactions
  • Loading branch information
TateB authored Jul 12, 2022
2 parents 3202169 + ecb4a6f commit 3202b00
Show file tree
Hide file tree
Showing 27 changed files with 400 additions and 328 deletions.
17 changes: 9 additions & 8 deletions packages/ensjs/src/functions/burnFuses.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber, ethers } from 'ethers'
import { ENS } from '..'
import { namehash } from '../utils/normalise'
import setup from '../tests/setup'
import { namehash } from '../utils/normalise'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand All @@ -22,16 +22,17 @@ describe('burnFuses', () => {
await revert()
})
it('should return a burnFuses transaction and succeed', async () => {
const wrapNameTx = await ENSInstance.wrapName(
'parthtejpal.eth',
accounts[0],
)
const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
wrappedOwner: accounts[0],
})
await wrapNameTx.wait()

const tx = await ENSInstance.burnFuses('parthtejpal.eth', {
cannotUnwrap: true,
cannotCreateSubdomain: true,
cannotSetTtl: true,
fusesToBurn: {
cannotUnwrap: true,
cannotCreateSubdomain: true,
cannotSetTtl: true,
},
})
expect(tx).toBeTruthy()
await tx.wait()
Expand Down
14 changes: 6 additions & 8 deletions packages/ensjs/src/functions/burnFuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import generateFuseInput from '../utils/generateFuseInput'
import { namehash } from '../utils/normalise'

export default async function (
{ contracts, provider }: ENSArgs<'contracts' | 'provider'>,
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
name: string,
fusesToBurn: FuseOptions,
{
fusesToBurn,
}: {
fusesToBurn: FuseOptions
},
) {
const signer = provider?.getSigner()

if (!signer) {
throw new Error('No signer found')
}

const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
const hash = namehash(name)

Expand Down
19 changes: 8 additions & 11 deletions packages/ensjs/src/functions/createSubname.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ENS } from '..'
import { namehash } from '../utils/normalise'
import setup from '../tests/setup'
import { namehash } from '../utils/normalise'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand All @@ -23,11 +23,10 @@ describe('createSubname', () => {
await revert()
})
it('should allow creating a subname on the registry', async () => {
const tx = await ENSInstance.createSubname({
const tx = await ENSInstance.createSubname('test.parthtejpal.eth', {
contract: 'registry',
name: 'test.parthtejpal.eth',
owner: accounts[0],
options: { addressOrIndex: 0 },
addressOrIndex: 0,
})
expect(tx).toBeTruthy()
await tx.wait()
Expand All @@ -37,16 +36,14 @@ describe('createSubname', () => {
expect(result).toBe(accounts[0])
})
it('should allow creating a subname on the namewrapper', async () => {
const wrapNameTx = await ENSInstance.wrapName(
'parthtejpal.eth',
accounts[0],
)
const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
wrappedOwner: accounts[0],
})
await wrapNameTx.wait()
const tx = await ENSInstance.createSubname({
const tx = await ENSInstance.createSubname('test.parthtejpal.eth', {
contract: 'nameWrapper',
name: 'test.parthtejpal.eth',
owner: accounts[0],
options: { addressOrIndex: 0 },
addressOrIndex: 0,
})
expect(tx).toBeTruthy()
await tx.wait()
Expand Down
13 changes: 3 additions & 10 deletions packages/ensjs/src/functions/createSubname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import generateFuseInput from '../utils/generateFuseInput'
import { namehash } from '../utils/normalise'

type BaseArgs = {
name: string
owner: string
resolverAddress?: string
contract: 'registry' | 'nameWrapper'
options?: { addressOrIndex?: string | number }
}

type NameWrapperArgs = {
Expand All @@ -20,15 +18,10 @@ type NameWrapperArgs = {
type Args = BaseArgs | NameWrapperArgs

export default async function (
{ contracts, provider }: ENSArgs<'contracts' | 'provider'>,
{ name, owner, resolverAddress, contract, options, ...wrapperArgs }: Args,
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
name: string,
{ owner, resolverAddress, contract, ...wrapperArgs }: Args,
) {
const signer = provider?.getSigner(options?.addressOrIndex)

if (!signer) {
throw new Error('No signer found')
}

const labels = name.split('.')

if (labels.length === 1) {
Expand Down
55 changes: 28 additions & 27 deletions packages/ensjs/src/functions/deleteSubname.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ENS } from '..'
import { namehash } from '../utils/normalise'
import setup from '../tests/setup'
import { namehash } from '../utils/normalise'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand All @@ -22,19 +22,20 @@ describe('deleteSubname', () => {
await revert()
})
it('should allow deleting a subname on the registry', async () => {
const createSubnameTx = await ENSInstance.createSubname({
contract: 'registry',
name: 'test.parthtejpal.eth',
owner: accounts[0],
options: { addressOrIndex: 0 },
})
await createSubnameTx.wait()

const tx = await ENSInstance.deleteSubname(
const createSubnameTx = await ENSInstance.createSubname(
'test.parthtejpal.eth',
'registry',
{ addressOrIndex: 0 },
{
contract: 'registry',
owner: accounts[0],
addressOrIndex: 0,
},
)
await createSubnameTx.wait()

const tx = await ENSInstance.deleteSubname('test.parthtejpal.eth', {
contract: 'registry',
addressOrIndex: 0,
})
expect(tx).toBeTruthy()
await tx.wait()

Expand All @@ -43,24 +44,24 @@ describe('deleteSubname', () => {
expect(result).toBe('0x0000000000000000000000000000000000000000')
})
it('should allow deleting a subname on the nameWrapper', async () => {
const wrapNameTx = await ENSInstance.wrapName(
'parthtejpal.eth',
accounts[0],
)
await wrapNameTx.wait()
const createSubnameTx = await ENSInstance.createSubname({
contract: 'nameWrapper',
name: 'test.parthtejpal.eth',
owner: accounts[0],
options: { addressOrIndex: 0 },
const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
wrappedOwner: accounts[0],
})
await createSubnameTx.wait()

const tx = await ENSInstance.deleteSubname(
await wrapNameTx.wait()
const createSubnameTx = await ENSInstance.createSubname(
'test.parthtejpal.eth',
'nameWrapper',
{ addressOrIndex: 0 },
{
contract: 'nameWrapper',
owner: accounts[0],
addressOrIndex: 0,
},
)
await createSubnameTx.wait()

const tx = await ENSInstance.deleteSubname('test.parthtejpal.eth', {
contract: 'nameWrapper',
addressOrIndex: 0,
})
expect(tx).toBeTruthy()
await tx.wait()

Expand Down
21 changes: 9 additions & 12 deletions packages/ensjs/src/functions/deleteSubname.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { ENSArgs } from '..'

export default async function (
{
contracts,
provider,
transferSubname,
}: ENSArgs<'contracts' | 'provider' | 'transferSubname'>,
{ transferSubname }: ENSArgs<'transferSubname'>,
name: string,
contract: 'registry' | 'nameWrapper',
options?: { addressOrIndex?: string | number },
{
contract,
}: {
contract: 'registry' | 'nameWrapper'
},
) {
return transferSubname(
name,
return transferSubname(name, {
contract,
'0x0000000000000000000000000000000000000000',
options,
)
address: '0x0000000000000000000000000000000000000000',
})
}
20 changes: 11 additions & 9 deletions packages/ensjs/src/functions/getFuses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ let withWrappedSnapshot: any
beforeAll(async () => {
;({ ENSInstance, revert, provider, createSnapshot } = await setup())
accounts = await provider.listAccounts()
const tx = await ENSInstance.wrapName('parthtejpal.eth', accounts[0])
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
wrappedOwner: accounts[0],
})
await tx.wait()

withWrappedSnapshot = await createSnapshot()
Expand All @@ -33,11 +35,10 @@ describe('getFuses', () => {
expect(result).toBeUndefined()
})
it('should return with canDoEverything set to true for a name with no fuses burned', async () => {
const tx = await ENSInstance.createSubname({
const tx = await ENSInstance.createSubname('test.parthtejpal.eth', {
contract: 'nameWrapper',
name: 'test.parthtejpal.eth',
owner: accounts[0],
options: { addressOrIndex: 0 },
addressOrIndex: 0,
})
await tx.wait()

Expand All @@ -56,9 +57,11 @@ describe('getFuses', () => {
})
it('should return with other correct fuses', async () => {
const tx = await ENSInstance.burnFuses('parthtejpal.eth', {
cannotUnwrap: true,
cannotSetTtl: true,
cannotCreateSubdomain: true,
fusesToBurn: {
cannotUnwrap: true,
cannotSetTtl: true,
cannotCreateSubdomain: true,
},
})
await tx.wait()
const result = await ENSInstance.getFuses('parthtejpal.eth')
Expand Down Expand Up @@ -86,8 +89,7 @@ describe('getFuses', () => {
}
})
it('should return correct vulnerability data for a vulnerable node', async () => {
const tx = await ENSInstance.createSubname({
name: 'test.parthtejpal.eth',
const tx = await ENSInstance.createSubname('test.parthtejpal.eth', {
owner: accounts[0],
contract: 'nameWrapper',
})
Expand Down
4 changes: 3 additions & 1 deletion packages/ensjs/src/functions/getOwner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let accounts: string[]
beforeAll(async () => {
;({ ENSInstance, revert, provider } = await setup())
accounts = await provider.listAccounts()
const tx = await ENSInstance.wrapName('parthtejpal.eth', accounts[0])
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
wrappedOwner: accounts[0],
})
await tx.wait()
})

Expand Down
5 changes: 3 additions & 2 deletions packages/ensjs/src/functions/setName.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ENS } from '..'
import { hexEncodeName } from '../utils/hexEncodedName'
import setup from '../tests/setup'
import { hexEncodeName } from '../utils/hexEncodedName'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand Down Expand Up @@ -43,7 +43,8 @@ describe('setName', () => {
)
await setApprovedForAllTx?.wait()

const tx = await ENSInstance.setName('fleek.eth', accounts[0], undefined, {
const tx = await ENSInstance.setName('fleek.eth', {
address: accounts[0],
addressOrIndex: 1,
})
expect(tx).toBeTruthy()
Expand Down
22 changes: 10 additions & 12 deletions packages/ensjs/src/functions/setName.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { ENSArgs } from '..'

export default async function (
{ contracts, provider }: ENSArgs<'contracts' | 'provider'>,
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
name: string,
address?: string,
resolver?: string,
options?: { addressOrIndex?: string | number },
{
address,
resolver,
}: {
address?: string
resolver?: string
} = {},
) {
const signerAddress = await provider
?.getSigner(options?.addressOrIndex)
.getAddress()

if (!signerAddress) {
throw new Error('No signer found')
}
const signerAddress = await signer.getAddress()

const reverseRegistrar = (await contracts?.getReverseRegistrar())?.connect(
provider?.getSigner()!,
signer,
)

if (address) {
Expand Down
12 changes: 7 additions & 5 deletions packages/ensjs/src/functions/setRecords.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ENS } from '..'
import setup from '../tests/setup'
import { hexEncodeName } from '../utils/hexEncodedName'
import { namehash } from '../utils/normalise'
import setup from '../tests/setup'

let ENSInstance: ENS
let revert: Awaited<ReturnType<typeof setup>>['revert']
Expand All @@ -17,10 +17,12 @@ afterAll(async () => {
describe('setRecords', () => {
it('should return a transaction to the resolver and set successfully', async () => {
const tx = await ENSInstance.setRecords('parthtejpal.eth', {
coinTypes: [
{ key: 'ETC', value: '0x42D63ae25990889E35F215bC95884039Ba354115' },
],
texts: [{ key: 'foo', value: 'bar' }],
records: {
coinTypes: [
{ key: 'ETC', value: '0x42D63ae25990889E35F215bC95884039Ba354115' },
],
texts: [{ key: 'foo', value: 'bar' }],
},
})
expect(tx).toBeTruthy()
await tx.wait()
Expand Down
Loading

0 comments on commit 3202b00

Please sign in to comment.