Copy it('Test transaction costs increase with each new refferal', async () => {
const { factory, signer, alice, bob } = await loadFixture(fixture);
const hashedCode = EthCrypto.hash.keccak256([
{ type: 'address', value: alice.address },
{ type: 'address', value: factory.address },
{ type: 'uint256', value: chainId },
]);
await factory.connect(alice).createReferralCode();
let nftName = 'Name';
let nftSymbol = 'AT';
const contractURI = 'contractURI/AccessToken123';
const price = ethers.utils.parseEther('0.01');
const feeNumerator = 500;
let message = EthCrypto.hash.keccak256([
{ type: 'string', value: nftName },
{ type: 'string', value: nftSymbol },
{ type: 'string', value: contractURI },
{ type: 'uint96' as any, value: feeNumerator },
{ type: 'uint256', value: chainId },
]);
let signature = EthCrypto.sign(signer.privateKey, message);
let tx = await factory.connect(bob).produce(
{
metadata: { name: nftName, symbol: nftSymbol },
contractURI: contractURI,
paymentToken: NATIVE_CURRENCY_ADDRESS,
mintPrice: price,
whitelistMintPrice: price,
transferable: true,
maxTotalSupply: BigNumber.from('1000'),
feeNumerator: feeNumerator,
collectionExpire: BigNumber.from('86400'),
signature: signature,
} as AccessTokenInfoStruct,
hashedCode,
)
let receipt = await tx.wait();
const firstGasUsed = receipt.gasUsed;
console.log(`This is the last receipt: ${ receipt.gasUsed}`)
let i = 0;
while( i < 100) {
let randomWallet = ethers.Wallet.createRandom().connect(ethers.provider);
await alice.sendTransaction({to: await randomWallet.getAddress(), value: ethers.utils.parseEther('0.1')})
let nftName = `Name ${ i++ }`;
let nftSymbol = `AT ${ i++ }`;
const contractURI = 'contractURI/AccessToken123';
const price = ethers.utils.parseEther('0.01');
const feeNumerator = 500;
let message = EthCrypto.hash.keccak256([
{ type: 'string', value: nftName },
{ type: 'string', value: nftSymbol },
{ type: 'string', value: contractURI },
{ type: 'uint96' as any, value: feeNumerator },
{ type: 'uint256', value: chainId },
]);
let signature = EthCrypto.sign(signer.privateKey, message);
tx = await factory.connect(randomWallet).produce(
{
metadata: { name: nftName, symbol: nftSymbol },
contractURI: contractURI,
paymentToken: NATIVE_CURRENCY_ADDRESS,
mintPrice: price,
whitelistMintPrice: price,
transferable: true,
maxTotalSupply: BigNumber.from('1000'),
feeNumerator: feeNumerator,
collectionExpire: BigNumber.from('86400'),
signature: signature,
} as AccessTokenInfoStruct,
hashedCode,
)
}
receipt = await tx.wait();
const diff = receipt.gasUsed.sub(firstGasUsed);
const secondCheckpointGasUsed = receipt.gasUsed;
console.log(`This is the last receipt gasUsed: ${secondCheckpointGasUsed}`)
assert(receipt.gasUsed != firstGasUsed && diff.gt(0n))
console.log(`The gas difference is after around 100 referrals: ${diff}`)
let j = 0;
while( j < 100) {
let randomWallet = ethers.Wallet.createRandom().connect(ethers.provider);
await alice.sendTransaction({to: await randomWallet.getAddress(), value: ethers.utils.parseEther('0.1')})
let nftName = `Name ${ i++ }`;
let nftSymbol = `AT ${ i++ }`;
const contractURI = 'contractURI/AccessToken123';
const price = ethers.utils.parseEther('0.01');
const feeNumerator = 500;
let message = EthCrypto.hash.keccak256([
{ type: 'string', value: nftName },
{ type: 'string', value: nftSymbol },
{ type: 'string', value: contractURI },
{ type: 'uint96' as any, value: feeNumerator },
{ type: 'uint256', value: chainId },
]);
let signature = EthCrypto.sign(signer.privateKey, message);
tx = await factory.connect(randomWallet).produce(
{
metadata: { name: nftName, symbol: nftSymbol },
contractURI: contractURI,
paymentToken: NATIVE_CURRENCY_ADDRESS,
mintPrice: price,
whitelistMintPrice: price,
transferable: true,
maxTotalSupply: BigNumber.from('1000'),
feeNumerator: feeNumerator,
collectionExpire: BigNumber.from('86400'),
signature: signature,
} as AccessTokenInfoStruct,
hashedCode,
)
j++;
}
receipt = await tx.wait();
const diff2 = receipt.gasUsed.sub(firstGasUsed);
console.log(`This is the receipt of gasUsed after 200 referrals: ${receipt.gasUsed}`)
assert(receipt.gasUsed != secondCheckpointGasUsed && diff2 != diff)
assert(receipt.gasUsed > secondCheckpointGasUsed && diff2 > diff)
console.log(`The gas difference is from first transaction after around 200 referals: ${diff2}`)
});