import { createLogger } from '@aztec/aztec.js/log';
import { ChildContract } from '@aztec/noir-test-contracts.js/Child';
import { ParentContract } from '@aztec/noir-test-contracts.js/Parent';
import { deployAccounts, publicDeployAccounts, setup, teardown as teardownSubsystems } from '../fixtures/setup.js';
export class NestedContractTest {
    numberOfAccounts;
    context;
    logger;
    wallet;
    defaultAccountAddress;
    aztecNode;
    parentContract;
    childContract;
    constructor(testName, numberOfAccounts = 1){
        this.numberOfAccounts = numberOfAccounts;
        this.logger = createLogger(`e2e:e2e_nested_contract:${testName}`);
    }
    /**
   * Applies base setup by deploying accounts and publicly deploying them.
   */ async applyBaseSetup() {
        this.logger.info('Deploying accounts');
        const { deployedAccounts } = await deployAccounts(this.numberOfAccounts, this.logger)({
            wallet: this.context.wallet,
            initialFundedAccounts: this.context.initialFundedAccounts
        });
        this.wallet = this.context.wallet;
        [{ address: this.defaultAccountAddress }] = deployedAccounts;
        this.aztecNode = this.context.aztecNodeService;
        this.logger.info('Public deploy accounts');
        await publicDeployAccounts(this.wallet, [
            this.defaultAccountAddress
        ]);
    }
    async setup() {
        this.logger.info('Setting up fresh subsystems');
        this.context = await setup(0, {
            fundSponsoredFPC: true,
            skipAccountDeployment: true
        });
        await this.applyBaseSetup();
    }
    async teardown() {
        await teardownSubsystems(this.context);
    }
    async applyManual() {
        this.logger.info('Deploying parent and child contracts');
        ({ contract: this.parentContract } = await ParentContract.deploy(this.wallet).send({
            from: this.defaultAccountAddress
        }));
        ({ contract: this.childContract } = await ChildContract.deploy(this.wallet).send({
            from: this.defaultAccountAddress
        }));
    }
}
