Skip to content

Commit

Permalink
chore: update builder test with convertSubnetTx
Browse files Browse the repository at this point in the history
  • Loading branch information
ruijialin-avalabs committed Oct 23, 2024
1 parent 52eb746 commit dab22dd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/vms/pvm/etna-builder/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
Signer,
TransferSubnetOwnershipTx,
AddPermissionlessDelegatorTx,
ConvertSubnetTx,
ProofOfPossession,
} from '../../../serializable/pvm';
import { BaseTx as AvaxBaseTx } from '../../../serializable/avax';
import { hexToBuffer } from '../../../utils';
Expand All @@ -48,6 +50,7 @@ import {
newAddPermissionlessValidatorTx,
newAddSubnetValidatorTx,
newBaseTx,
newConvertSubnetTx,
newCreateChainTx,
newCreateSubnetTx,
newExportTx,
Expand All @@ -67,6 +70,8 @@ import {
proofOfPossession,
} from '../../../fixtures/pvm';
import type { FeeState } from '../models';
import { ConvertSubnetValidator } from '../../../serializable/fxs/pvm/convertSubnetValidator';
import { PChainOwner } from '../../../serializable/fxs/pvm/pChainOwner';

const addTransferableAmounts = (
transferableItems:
Expand Down Expand Up @@ -1007,4 +1012,68 @@ describe('./src/vms/pvm/etna-builder/builder.test.ts', () => {
expectTxs(unsignedTx.getTx(), expectedTx);
});
});

describe('ConvertSubnetTx', () => {
it('should create an ConvertSubnetTx', () => {
const utxoInputAmt = BigInt(50 * 1e9);
const utxos = testUtxos();
const signer = new ProofOfPossession(
blsPublicKeyBytes(),
blsSignatureBytes(),
);
const pChainOwner = PChainOwner.fromNative([testAddress1], 1);

const validator = ConvertSubnetValidator.fromNative(
nodeId,
BigInt(1 * 1e9),
BigInt(0 * 1e9),
signer,
pChainOwner,
pChainOwner,
);

const unsignedTx = newConvertSubnetTx(
{
fromAddressesBytes,
feeState,
utxos,
subnetAuth: [0],
subnetId: Id.fromHex(testSubnetId).toString(),
address: testAddress1,
validators: [validator],
chainId: 'h5vH4Zz53MTN2jf72axZCfo1VbG1cMR6giR4Ra2TTpEmqxDWB',
},
testContext,
);

const { baseTx } = unsignedTx.getTx() as ConvertSubnetTx;
const { inputs, outputs } = baseTx;

const [amountConsumed, expectedAmountConsumed, expectedFee] =
checkFeeIsCorrect({
unsignedTx,
inputs,
outputs,
feeState,
});

expect(amountConsumed).toEqual(expectedAmountConsumed);

const expectedTx = new ConvertSubnetTx(
AvaxBaseTx.fromNative(
testContext.networkID,
testContext.pBlockchainID,
[getTransferableOutForTest(utxoInputAmt - expectedFee)],
[getTransferableInputForTest(utxoInputAmt)],
new Uint8Array(),
),
Id.fromHex(testSubnetId),
Id.fromString('h5vH4Zz53MTN2jf72axZCfo1VbG1cMR6giR4Ra2TTpEmqxDWB'),
new Bytes(testAddress1),
[validator],
Input.fromNative([0]),
);
expectTxs(unsignedTx.getTx(), expectedTx);
});
});
});
2 changes: 2 additions & 0 deletions src/vms/pvm/etna-builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
import { spend } from './spend';
import { useSpendableLockedUTXOs, useUnlockedUTXOs } from './spend-reducers';
import type { ConvertSubnetValidator } from '../../../serializable/fxs/pvm/convertSubnetValidator';
import { INTRINSIC_CONVERT_SUBNET_TX_COMPLEXITIES } from '../txs/fee/constants';

/**
* Creates OutputOwners used for change outputs with the specified
Expand Down Expand Up @@ -1391,6 +1392,7 @@ export const newConvertSubnetTx: TxBuilderFn<NewConvertSubnetTxProps> = (
}

const complexity = addDimensions(
INTRINSIC_CONVERT_SUBNET_TX_COMPLEXITIES,
bytesComplexity,
validatorComplexity,
authComplexity,
Expand Down

0 comments on commit dab22dd

Please sign in to comment.