Skip to content

Commit

Permalink
chore: sort test folder
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Aug 28, 2024
1 parent cd3fe4a commit 16c526d
Show file tree
Hide file tree
Showing 43 changed files with 4,398 additions and 255 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"execa": "^9.3.1",
"get-port": "^7.1.0",
"gh-pages": "^6.1.1",
"nexus": "github:bcnmy/nexus#f08ec9f2d6cd2cf0044b901cc4c4a1cb5c527273",
"nexus": "github:bcnmy/nexus#179c0c6ce0c65faf23a40fbf1f9e9dde1ea71bf7",
"prool": "^0.0.16",
"rimraf": "^5.0.5",
"simple-git-hooks": "^2.9.0",
Expand Down
14 changes: 8 additions & 6 deletions scripts/fetch:deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const getDeployments = async () => {

const tsAbiPath = isForCore
? `${__dirname}/../src/__contracts/abi/${name}Abi.ts`
: `${__dirname}/../tests/__contracts/abi/${name}Abi.ts`
: `${__dirname}/../tests/src/__contracts/abi/${name}Abi.ts`

fs.writeFileSync(tsAbiPath, tsAbiContent)

Expand All @@ -66,14 +66,15 @@ export const getDeployments = async () => {
const abiIndexPath = `${__dirname}/../src/__contracts/abi/index.ts`
fs.writeFileSync(abiIndexPath, abiIndexContent)

const testAbiIndexPath = `${__dirname}/../tests/__contracts/abi/index.ts`
const testAbiIndexPath = `${__dirname}/../tests/src/__contracts/abi/index.ts`
fs.writeFileSync(testAbiIndexPath, testAbiIndexContent)

// Write addresses to src folder
const writeAddressesPath = `${__dirname}/../src/__contracts/addresses.ts`
const writeAddressesPathTest = `${__dirname}/../tests/__contracts/addresses.ts`
const writeAddressesPathTest = `${__dirname}/../tests/src/__contracts/mockAddresses.ts`

const addressesContent = `import type { Hex } from "viem"\nexport const addresses: Record<string, Hex> = ${JSON.stringify(
const addressesContent = `// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten\n
import type { Hex } from "viem"\nexport const addresses: Record<string, Hex> = ${JSON.stringify(
Object.keys(deployedContracts)
.filter((key) => coreFiles.includes(key))
.reduce((acc, key) => {
Expand All @@ -84,7 +85,8 @@ export const getDeployments = async () => {
2
)} as const;\nexport default addresses\n`

const testAddressesContent = `import type { Hex } from "viem"\nexport const addresses: Record<string, Hex> = ${JSON.stringify(
const testAddressesContent = `// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten\n
import type { Hex } from "viem"\nexport const mockAddresses: Record<string, Hex> = ${JSON.stringify(
Object.keys(deployedContracts)
.filter((key) => testFiles.includes(key))
.reduce((acc, key) => {
Expand All @@ -93,7 +95,7 @@ export const getDeployments = async () => {
}, {}),
null,
2
)} as const;\nexport default addresses\n`
)} as const;\nexport default mockAddresses\n`

fs.writeFileSync(writeAddressesPath, addressesContent)
fs.writeFileSync(writeAddressesPathTest, testAddressesContent)
Expand Down
1 change: 0 additions & 1 deletion src/__contracts/README.md

This file was deleted.

6 changes: 3 additions & 3 deletions src/__contracts/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Hex } from "viem"
export const addresses: Record<string, Hex> = {
Nexus: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
K1Validator: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
K1ValidatorFactory: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
Nexus: "0x776d63154D2aa9256D72C420416c930F3B735464",
K1Validator: "0xd98238BBAeA4f91683d250003799EAd31d7F5c55",
K1ValidatorFactory: "0x8025afaD10209b8bEF3A3C94684AaE4D309c9996"
} as const
export default addresses
95 changes: 50 additions & 45 deletions src/account/NexusSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
} from "../paymaster/index.js"
import {
BaseSmartContractAccount,
type DeploymentState
DeploymentState
} from "./BaseSmartContractAccount.js"
import {
Logger,
Expand Down Expand Up @@ -169,15 +169,7 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
nexusSmartAccountConfig.activeValidationModule!

// this.publicClient = createPublicClient({
// chain,
// transport: http(rpcClient)
// })

// this.scanForUpgradedAccountsFromV1 =
// nexusSmartAccountConfig.scanForUpgradedAccountsFromV1 ?? false
// this.maxIndexForScan = nexusSmartAccountConfig.maxIndexForScan ?? 10n
// this.getAddress()
this.getDeploymentState()
}

/**
Expand Down Expand Up @@ -323,13 +315,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl, paymasterUrl }); // Retrieve bundler/paymaster url from dashboard
* const encodedCall = encodeFunctionData({
* abi: parseAbi(["function safeMint(address to) public"]),
* functionName: "safeMint",
* abi: CounterAbi,
* functionName: "incrementNumber",
* args: ["0x..."],
* });
*
* const tx = {
* to: nftAddress,
* to: mockAddresses.Counter,
* data: encodedCall
* }
*
Expand Down Expand Up @@ -591,14 +583,17 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
async _getAccountContract(): Promise<
GetContractReturnType<typeof NexusAbi, PublicClient>
> {
if (this.accountContract == null) {
this.accountContract = getContract({
address: await this.getAddress(),
abi: NexusAbi,
client: this.publicClient as PublicClient
})
if (await this.isAccountDeployed()) {
if (!this.accountContract) {
this.accountContract = getContract({
address: await this.getAddress(),
abi: NexusAbi,
client: this.publicClient as PublicClient
})
}
return this.accountContract
}
return this.accountContract
throw new Error(ERROR_MESSAGES.ACCOUNT_NOT_DEPLOYED)
}

isActiveValidationModuleDefined(): boolean {
Expand Down Expand Up @@ -676,10 +671,6 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
return this
}

setDeploymentState(deploymentState: DeploymentState) {
this.deploymentState = deploymentState
}

// async getV1AccountsUpgradedToV2(
// params: QueryParamsForAddressResolver
// ): Promise<Hex> {
Expand Down Expand Up @@ -899,13 +890,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl }); // Retrieve bundler url from dashboard
* const encodedCall = encodeFunctionData({
* abi: parseAbi(["function safeMint(address to) public"]),
* functionName: "safeMint",
* abi: CounterAbi,
* functionName: "incrementNumber",
* args: ["0x..."],
* });
*
* const transaction = {
* to: nftAddress,
* to: mockAddresses.Counter,
* data: encodedCall
* }
*
Expand Down Expand Up @@ -1028,13 +1019,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl }); // Retrieve bundler url from dashboard
* const encodedCall = encodeFunctionData({
* abi: parseAbi(["function safeMint(address to) public"]),
* functionName: "safeMint",
* abi: CounterAbi,
* functionName: "incrementNumber",
* args: ["0x..."],
* });
*
* const transaction = {
* to: nftAddress,
* to: mockAddresses.Counter,
* data: encodedCall
* }
*
Expand Down Expand Up @@ -1273,13 +1264,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl }); // Retrieve bundler url from dashboard
* const encodedCall = encodeFunctionData({
* abi: parseAbi(["function safeMint(address to) public"]),
* functionName: "safeMint",
* abi: CounterAbi,
* functionName: "incrementNumber",
* args: ["0x..."],
* });
*
* const transaction = {
* to: nftAddress,
* to: mockAddresses.Counter,
* data: encodedCall
* }
*
Expand All @@ -1302,13 +1293,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl }); // Retrieve bundler url from dashboard
* const encodedCall = encodeFunctionData({
* abi: parseAbi(["function safeMint(address to) public"]),
* functionName: "safeMint",
* abi: CounterAbi,
* functionName: "incrementNumber",
* args: ["0x..."],
* });
*
* const transaction = {
* to: nftAddress,
* to: mockAddresses.Counter,
* data: encodedCall
* }
*
Expand All @@ -1331,7 +1322,17 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
: [manyOrOneTransactions],
buildUseropDto
)
return this.sendUserOp(userOp)
const payload = await this.sendUserOp(userOp)
this.setDeploymentState(payload) // Don't wait
return payload
}

private async setDeploymentState({ wait }: UserOpResponse) {
if (this.deploymentState === DeploymentState.DEPLOYED) return
const { success } = await wait()
if (success) {
this.deploymentState = DeploymentState.DEPLOYED
}
}

async sendTransactionWithExecutor(
Expand Down Expand Up @@ -1373,13 +1374,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
*
* const smartAccount = await createSmartAccountClient({ signer, bundlerUrl }); // Retrieve bundler url from dashboard
* const encodedCall = encodeFunctionData({
* abi: parseAbi(["function safeMint(address to) public"]),
* functionName: "safeMint",
* abi: CounterAbi,
* functionName: "incrementNumber",
* args: ["0x..."],
* });
*
* const transaction = {
* to: nftAddress,
* to: mockAddresses.Counter,
* data: encodedCall
* }
*
Expand Down Expand Up @@ -1413,12 +1414,13 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
sender: (await this.getAddress()) as Hex,
nonce: nonceFromFetch,
factoryData,
factory: (await this.isAccountDeployed())
? undefined
: this.factoryAddress,
callData
}

if (!(await this.isAccountDeployed())) {
userOp.factory = this.factoryAddress
}

userOp.signature = dummySignature

const gasFeeValues: GetUserOperationGasPriceReturnType | undefined =
Expand Down Expand Up @@ -1722,11 +1724,11 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
async isModuleInstalled(module: Module) {
if (await this.isAccountDeployed()) {
const accountContract = await this._getAccountContract()
return (await accountContract.read.isModuleInstalled([
return await accountContract.read.isModuleInstalled([
BigInt(moduleTypeIds[module.type]),
module.moduleAddress,
module.data ?? "0x"
])) as boolean
])
}
Logger.warn("A module cannot be installed on an undeployed account")
return false
Expand Down Expand Up @@ -2006,7 +2008,10 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
const executors = await this.getInstalledExecutors()
const hook = await this.getActiveHook()
const fallbackHandler = await this.getFallbackBySelector()

return [...validators, ...executors, hook, fallbackHandler]
.flat()
.filter(Boolean)
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/modules/utils/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ModuleVersion } from "./Types.js"

export const OWNABLE_EXECUTOR = "0x"
export const OWNABLE_VALIDATOR = "0x"
export const DEFAULT_MODULE_VERSION: ModuleVersion = "1.0.0-beta"
3 changes: 2 additions & 1 deletion src/modules/validators/K1ValidatorModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Address } from "viem"

Check failure on line 1 in src/modules/validators/K1ValidatorModule.ts

View workflow job for this annotation

GitHub Actions / size report

'Address' is declared but its value is never read.
import addresses from "../../__contracts/addresses.js"
import type { SmartAccountSigner } from "../../account/index.js"
import { BaseValidationModule } from "../base/BaseValidationModule.js"
import type { Module } from "../utils/Types.js"
Expand All @@ -10,7 +11,7 @@ export class K1ValidatorModule extends BaseValidationModule {

public static async create(
signer: SmartAccountSigner,
k1ValidatorAddress: Address
k1ValidatorAddress = addresses.K1Validator
): Promise<K1ValidatorModule> {
const module: Module = {
moduleAddress: k1ValidatorAddress,
Expand Down
1 change: 0 additions & 1 deletion tests/__contracts/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions tests/__contracts/abi/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions tests/__contracts/addresses.ts

This file was deleted.

23 changes: 0 additions & 23 deletions tests/__contracts/deployment.json

This file was deleted.

Loading

0 comments on commit 16c526d

Please sign in to comment.