Skip to content

Commit

Permalink
wip 3
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Apr 12, 2024
1 parent a6a250e commit c735451
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
22 changes: 22 additions & 0 deletions networks/hardhat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"contractName": "WalletFactory",
"address": "0xFaA5c0b14d1bED5C888Ca655B9a8A5911F78eF4A"
},
{
"contractName": "MainModule",
"address": "0xE1846F966D116B86d65481Fe81886219D698b60D"
},
{
"contractName": "MainModuleUpgradable",
"address": "0xB39E1ed61caC9E8eE8CDD3218765cF6a7fE390db"
},
{
"contractName": "GuestModule",
"address": "0x28Ec0675C7b40ed78EBcBBbDF39e5652c0787B18"
},
{
"contractName": "SequenceUtils",
"address": "0x4817Fe9f2352E88991A7c84E4385708Ccff05704"
}
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "hardhat test",
"benchmark": "BENCHMARK=true pnpm test",
"coverage": "COVERAGE=true NET_ID=1 hardhat coverage",
"deploy": "hardhat run utils/deploy-contracts.ts --network",
"deploy": "hardhat run utils/deploy-contracts.ts --network hardhat",
"verify": "hardhat verify --network",
"release": "pnpm publish src",
"lint": "pnpm lint:ts && pnpm lint:sol",
Expand Down
5 changes: 5 additions & 0 deletions test/Factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ contract('Factory', () => {
beforeEach(async () => {
module = await ModuleMock.deploy()
factory = await Factory.deploy()

await module.waitForDeployment()
await factory.waitForDeployment()
})

describe('Deploy wallets', () => {
Expand All @@ -20,12 +23,14 @@ contract('Factory', () => {
await module.getAddress(),
ethers.AbiCoder.defaultAbiCoder().encode(['address'], [ethers.Wallet.createRandom().address])
)
await factory.waitForDeployment()
})

it('Should predict wallet address', async () => {
const hash = ethers.hexlify(ethers.randomBytes(32))
const predict = addressOf(await factory.getAddress(), await module.getAddress(), hash)
await factory.deploy(await module.getAddress(), hash)
await factory.waitForDeployment()
expect(await hethers.provider.getCode(predict)).to.not.equal('0x')
})

Expand Down
1 change: 1 addition & 0 deletions test/MainModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract('MainModule', (accounts: string[]) => {

beforeEach(async () => {
callReceiver = await CallReceiverMock.deploy()
await callReceiver.waitForDeployment()

wallet = SequenceWallet.basicWallet(context)
await wallet.deploy()
Expand Down
6 changes: 5 additions & 1 deletion test/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export const deploySequenceContext = async (owner?: string) => {
const mainModuleUpgradable = await MainModuleUpgradable.deploy()
const mainModule = await MainModule.deploy(await factory.getAddress(), await mainModuleUpgradable.getAddress())

return { factory, mainModule, mainModuleUpgradable }
return {
factory: await factory.waitForDeployment(),
mainModule: await mainModule.waitForDeployment(),
mainModuleUpgradable: await mainModuleUpgradable.waitForDeployment()
}
}

export type SequenceContext = {
Expand Down
24 changes: 13 additions & 11 deletions test/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ export class SequenceWallet {
public isSequence = true
_isSigner: boolean = true

factoryAddress: string = ethers.ZeroAddress
mainModuleAddress: string = ethers.ZeroAddress

constructor(public options: WalletOptions) {
this.options.context.factory.getAddress().then(address => (this.factoryAddress = address))
this.options.context.mainModule.getAddress().then(address => (this.mainModuleAddress = address))
}
constructor(public options: WalletOptions) {}

static basicWallet(context: SequenceContext, opts?: Partial<BasicWalletOptions>): SequenceWallet {
const options = { ...{ signing: 1, idle: 0, topologyConverter: defaultTopology }, ...opts }
Expand Down Expand Up @@ -188,7 +182,11 @@ export class SequenceWallet {

get address() {
if (this.options.address) return this.options.address
return addressOf(this.factoryAddress, this.mainModuleAddress, this.imageHash)
return addressOf(
this.options.context.factory.target as string,
this.options.context.mainModule.target as string,
this.imageHash
)
}

getAddress() {
Expand All @@ -212,14 +210,15 @@ export class SequenceWallet {
return
}

return this.options.context.factory.deploy(await this.options.context.mainModule.getAddress(), this.imageHash)
await this.options.context.factory.deploy(await this.options.context.mainModule.getAddress(), this.imageHash)
return this.options.context.factory.waitForDeployment()
}

async getNonce(space: ethers.BigNumberish = 0) {
return this.mainModule.readNonce(space)
}

async updateImageHash(input: ethers.BytesLike | WalletConfig) {
async updateImageHash(input: ethers.BytesLike | WalletConfig): Promise<ethers.ContractTransactionResponse> {
if (!ethers.isBytesLike(input)) return this.updateImageHash(imageHash(input))

return this.sendTransactions([
Expand All @@ -230,7 +229,10 @@ export class SequenceWallet {
])
}

async addExtraImageHash(input: ethers.BytesLike | WalletConfig, expiration: ethers.BigNumberish = 2n ** 248n) {
async addExtraImageHash(
input: ethers.BytesLike | WalletConfig,
expiration: ethers.BigNumberish = 2n ** 248n
): Promise<ethers.ContractTransactionResponse> {
if (!ethers.isBytesLike(input)) return this.addExtraImageHash(imageHash(input))

return this.sendTransactions([
Expand Down

0 comments on commit c735451

Please sign in to comment.