Skip to content

Commit

Permalink
test: changing primitive props together
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed May 9, 2022
1 parent a1274ed commit eccf425
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/plugins/candyMachineModule/updateCandyMachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,75 @@ test('update: candy machine single property', async (t) => {
currentCandyMachine = updatedMachine!;
}
});

test.only('update: candy machine multiple properties', async (t) => {
// Given I create one candy machine
const mx = await metaplex();
const { candyMachineSigner, payerSigner, walletAddress, candyMachine } =
await createCandyMachineWithMinimalConfig(mx);

const changes: [keyof CandyMachineData, ValueOf<CandyMachineData>][][] = [
// first half
[
['uuid', 'new-uuid'],
['price', 333],
['symbol', 'NEW'],
],
// second half
[
['sellerFeeBasisPoints', 555],
['isMutable', true],
['retainAuthority', false],
['goLiveDate', new Date('2022-02-02').valueOf()],
],

// all
[
['uuid', 'new-uuid'],
['price', 333],
['symbol', 'NEW'],
['sellerFeeBasisPoints', 555],
['isMutable', true],
['retainAuthority', false],
['goLiveDate', new Date('2022-02-02').valueOf()],
],
];

let currentCandyMachine = candyMachine;
for (const changeSet of changes) {
const keys = changeSet.map(([key]) => key);

t.comment(`+++ Updating ${keys.join(', ')}`);

// When I update that candy machine's property
const candyMachineData = currentCandyMachine.candyMachineData;
for (const [key, value] of changeSet) {
(candyMachineData as Record<keyof CandyMachineData, ValueOf<CandyMachineData>>)[key] = value;
}

const cm = mx.candyMachines();
const { transactionId, confirmResponse } = await cm.updateCandyMachine({
authoritySigner: payerSigner,
candyMachineAddress: candyMachineSigner.publicKey,
walletAddress,
...candyMachineData,
});
await amman.addr.addLabel(`tx: update-cm-${keys.join(', ')}`, transactionId);

// Then the transaction succeeds
assertConfirmedWithoutError(t, cusper, confirmResponse);

// And the candy machine is updated
const updatedMachine = await mx
.candyMachines()
.findCandyMachineByAddress(candyMachineSigner.publicKey);
t.ok(updatedMachine != null, 'finds updated machine');

const expectedChanges = changeSet.reduce((acc, [key, val]) => {
(acc as Record<keyof CandyMachineData, ValueOf<CandyMachineData>>)[key] = val;
return acc;
}, {});
assertProperlyUpdated(t, currentCandyMachine, updatedMachine!, expectedChanges);
currentCandyMachine = updatedMachine!;
}
});

0 comments on commit eccf425

Please sign in to comment.