Skip to content

Commit 5e6ce59

Browse files
committed
feat: etna builder wrap up bug fixes and tests
1 parent 62cabd2 commit 5e6ce59

File tree

4 files changed

+8
-26
lines changed

4 files changed

+8
-26
lines changed

src/vms/pvm/etna-builder/builder.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,11 @@ describe('./src/vms/pvm/etna-builder/builder.test.ts', () => {
289289
[
290290
TransferableOutput.fromNative(
291291
testContext.avaxAssetID,
292-
// TODO: What is the expected value here?
293-
49_999_000_000n - expectedFee,
292+
// TODO: How to remove this "magic" number. How do we calculate it correctly from utxos?
293+
50_000_000_000n - expectedFee,
294294
[testAddress1],
295295
),
296296
],
297-
// TODO: Add an input here?
298297
[],
299298
memo ?? new Uint8Array(),
300299
),
@@ -348,7 +347,7 @@ describe('./src/vms/pvm/etna-builder/builder.test.ts', () => {
348347
[
349348
TransferableOutput.fromNative(
350349
testContext.avaxAssetID,
351-
// TODO: Possibly need to adjust this value?
350+
// TODO: Remove magic number. How to calculate it correctly from utxos?
352351
45_000_000_000n - expectedFee,
353352
fromAddressesBytes,
354353
),

src/vms/pvm/etna-builder/builder.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ export const newBaseTx: TxBuilderFn<NewBaseTxProps> = (
161161
const [error, spendResults] = spend(
162162
{
163163
complexity,
164-
// TODO: Check this
165164
excessAVAX: 0n,
166165
fromAddresses,
167166
spendOptions: defaultedOptions,
@@ -330,8 +329,6 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
330329
excessAVAX = importedAvax - context.baseTxFee;
331330
}
332331

333-
console.log('excessAVAX', excessAVAX);
334-
335332
const [error, spendResults] = spend(
336333
{
337334
complexity,
@@ -351,11 +348,6 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
351348

352349
const { changeOutputs, inputs, inputUTXOs } = spendResults;
353350

354-
// NOTE: ChangeOutput amount should equal the excessAVAX amount.
355-
console.log('changeOutputs', changeOutputs);
356-
// NOTE: Inputs should be an empty array.
357-
console.log('inputs', inputs);
358-
359351
return new UnsignedTx(
360352
new ImportTx(
361353
new AvaxBaseTx(
@@ -420,7 +412,6 @@ export const newExportTx: TxBuilderFn<NewExportTxProps> = (
420412
const [error, spendResults] = spend(
421413
{
422414
complexity,
423-
// TODO: Check this
424415
excessAVAX: 0n,
425416
fromAddresses,
426417
spendOptions: defaultedOptions,
@@ -499,7 +490,6 @@ export const newCreateSubnetTx: TxBuilderFn<NewCreateSubnetTxProps> = (
499490
const [error, spendResults] = spend(
500491
{
501492
complexity,
502-
// TODO: Check this
503493
excessAVAX: 0n,
504494
fromAddresses: addressesFromBytes(fromAddressesBytes),
505495
spendOptions: defaultedOptions,
@@ -612,7 +602,6 @@ export const newCreateChainTx: TxBuilderFn<NewCreateChainTxProps> = (
612602
const [error, spendResults] = spend(
613603
{
614604
complexity,
615-
// TODO: Check this
616605
excessAVAX: 0n,
617606
fromAddresses: addressesFromBytes(fromAddressesBytes),
618607
spendOptions: defaultedOptions,
@@ -707,7 +696,6 @@ export const newAddSubnetValidatorTx: TxBuilderFn<
707696
const [error, spendResults] = spend(
708697
{
709698
complexity,
710-
// TODO: Check this
711699
excessAVAX: 0n,
712700
fromAddresses: addressesFromBytes(fromAddressesBytes),
713701
spendOptions: defaultedOptions,
@@ -791,7 +779,6 @@ export const newRemoveSubnetValidatorTx: TxBuilderFn<
791779
const [error, spendResults] = spend(
792780
{
793781
complexity,
794-
// TODO: Check this
795782
excessAVAX: 0n,
796783
fromAddresses: addressesFromBytes(fromAddressesBytes),
797784
spendOptions: defaultedOptions,
@@ -964,7 +951,6 @@ export const newAddPermissionlessValidatorTx: TxBuilderFn<
964951
const [error, spendResults] = spend(
965952
{
966953
complexity,
967-
// TODO: Check this
968954
excessAVAX: 0n,
969955
fromAddresses: addressesFromBytes(fromAddressesBytes),
970956
spendOptions: defaultedOptions,
@@ -1118,7 +1104,6 @@ export const newAddPermissionlessDelegatorTx: TxBuilderFn<
11181104
const [error, spendResults] = spend(
11191105
{
11201106
complexity,
1121-
// TODO: Check this
11221107
excessAVAX: 0n,
11231108
fromAddresses: addressesFromBytes(fromAddressesBytes),
11241109
spendOptions: defaultedOptions,
@@ -1233,7 +1218,6 @@ export const newTransferSubnetOwnershipTx: TxBuilderFn<
12331218
const [error, spendResults] = spend(
12341219
{
12351220
complexity,
1236-
// TODO: Check this
12371221
excessAVAX: 0n,
12381222
fromAddresses: addressesFromBytes(fromAddressesBytes),
12391223
spendOptions: defaultedOptions,

src/vms/pvm/etna-builder/spend.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type SpendProps = Readonly<{
141141
* Contains the amount of extra AVAX that spend can produce in
142142
* the change outputs in addition to the consumed and not burned AVAX.
143143
*/
144-
excessAVAX: bigint;
144+
excessAVAX?: bigint;
145145
/**
146146
* List of Addresses that are used for selecting which UTXOs are signable.
147147
*/
@@ -187,7 +187,7 @@ type SpendProps = Readonly<{
187187
export const spend = (
188188
{
189189
complexity,
190-
excessAVAX: _excessAVAX,
190+
excessAVAX: _excessAVAX = 0n,
191191
fromAddresses,
192192
ownerOverride: _ownerOverride,
193193
spendOptions,
@@ -246,7 +246,6 @@ export const spend = (
246246
spendHelper.addInput(
247247
utxo,
248248
// TODO: Verify this.
249-
// TransferableInput.fromUtxoAndSigindicies(utxo, inputSigIndices),
250249
new TransferableInput(
251250
utxo.utxoId,
252251
utxo.assetId,
@@ -403,7 +402,6 @@ export const spend = (
403402
spendHelper.addInput(
404403
utxo,
405404
// TODO: Verify this.
406-
// TransferableInput.fromUtxoAndSigindicies(utxo, inputSigIndices),
407405
new TransferableInput(
408406
utxo.utxoId,
409407
utxo.assetId,

src/vms/pvm/etna-builder/spendHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class SpendHelper {
123123
* @returns {boolean} - Returns true if the asset should be consumed, false otherwise.
124124
*/
125125
shouldConsumeLockedAsset(assetId: string): boolean {
126-
return this.toStake.get(assetId) !== 0n;
126+
return this.toStake.has(assetId) && this.toStake.get(assetId) !== 0n;
127127
}
128128

129129
/**
@@ -134,7 +134,8 @@ export class SpendHelper {
134134
*/
135135
shouldConsumeAsset(assetId: string): boolean {
136136
return (
137-
this.toBurn.get(assetId) !== 0n || this.shouldConsumeLockedAsset(assetId)
137+
(this.toBurn.has(assetId) && this.toBurn.get(assetId) !== 0n) ||
138+
this.shouldConsumeLockedAsset(assetId)
138139
);
139140
}
140141

0 commit comments

Comments
 (0)