Skip to content

Commit

Permalink
fix: Default contract deploys to Clarity version 3 (#1756)
Browse files Browse the repository at this point in the history
* fix: Default contract deploys to Clarity version 3

* test: update clarity version tests

* docs: update migration guide

---------

Co-authored-by: janniks <janniks@users.noreply.github.com>
  • Loading branch information
janniks and janniks authored Nov 14, 2024
1 parent 2f2b12b commit 748e1e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [Stacks.js (\>=5.x.x) → (7.x.x)](#stacksjs-5xx--7xx)
- [Breaking Changes](#breaking-changes)
- [Reducing Wrapper Types](#reducing-wrapper-types)
- [Clarity Version](#clarity-version)
- [Stacks Network](#stacks-network)
- [Impacts](#impacts)
- [Clarity Representation](#clarity-representation)
Expand Down Expand Up @@ -34,6 +35,7 @@
### Breaking Changes

- The `@stacks/network` `new StacksNetwork()` objects were removed. Instead `@stacks/network` now exports the objects `STACKS_MAINNET`, `STACKS_TESNET`, and `STACKS_DEVNET`, which are static (and shouldn't be changed for most use-cases). [Read more...](#stacks-network)
- Contract Deploys now default to Clarity version 3. [Read more...](#clarity-version)
- Most `fetch` (aka networking) methods were renamed to indicate they send HTTP requests. The new methods are named `fetchXyz` and are compatible with the old `Xyz` interfaces. [Read more...](#fetch-methods)
- Reducing wrapper types, which create annoyances for the developer, rather than being able to use values directly. [Read more...](#reducing-wrapper-types)
- The `ClarityType` enum was replaced by a human-readable version. The previous (wire format compatible) enum is still available as `ClarityWireType`. [Read more...](#clarity-representation)
Expand All @@ -55,6 +57,10 @@ This breaks the signatures of many functions:
- `signMessageHashRsv`, `signWithKey` now return the message signature as a `string` directly.
- `nextSignature`, `nextVerification`, `publicKeyFromSignatureVrs`, `publicKeyFromSignatureRsv` now take in the message signature as a `string`.

### Clarity Version

Contract Deploys now default to Clarity version `3`, which is the latest version introduced with the Stacks Nakamoto update.

### Stacks Network

From now on "network" objects are static (aka constants) and don't require instantiation.
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export async function makeUnsignedContractDeploy(
network: STACKS_MAINNET,
postConditionMode: PostConditionMode.Deny,
sponsored: false,
clarityVersion: ClarityVersion.Clarity2,
clarityVersion: ClarityVersion.Clarity3,
};

const options = Object.assign(defaultOptions, txOptions);
Expand Down
28 changes: 27 additions & 1 deletion packages/transactions/tests/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ test('Make smart contract deploy (defaults to versioned smart contract, as of 2.
senderKey,
fee,
nonce,
clarityVersion: 2,
network: STACKS_TESTNET,
});
expect(() => transaction.verifyOrigin()).not.toThrow();
Expand All @@ -728,11 +729,12 @@ test('Make smart contract deploy (defaults to versioned smart contract, as of 2.
expect(serialized).toBe(tx);
});

test('Make smart contract deploy with network string name (defaults to versioned smart contract, as of 2.1)', async () => {
test('Make smart contract deploy with network string name (versioned smart contracts exist, as of 2.1)', async () => {
const transaction = await makeContractDeploy({
contractName: 'kv-store',
codeBody: fs.readFileSync('./tests/contracts/kv-store.clar').toString(),
senderKey: 'e494f188c2d35887531ba474c433b1e41fadd8eb824aca983447fd4bb8b277a801',
clarityVersion: ClarityVersion.Clarity2,
fee: 0,
nonce: 0,
network: 'testnet',
Expand All @@ -741,12 +743,36 @@ test('Make smart contract deploy with network string name (defaults to versioned

const serialized = transaction.serialize();

expect(serialized[233]).toBe('2');

const tx =
'80800000000400e6c05355e0c990ffad19a5e9bda394a9c50034290000000000000000000000000000000000009172c9841e763c32e827c177491f5228956e6ef1071043be898bfdd694bf3e680309b0666e8fec013a8a453573a8bd707152c9f21aa6f2d5e57c407af672b6f00302000000000602086b762d73746f72650000015628646566696e652d6d61702073746f72652028286b657920286275666620333229292920282876616c7565202862756666203332292929290a0a28646566696e652d7075626c696320286765742d76616c756520286b65792028627566662033322929290a20202020286d6174636820286d61702d6765743f2073746f72652028286b6579206b65792929290a2020202020202020656e74727920286f6b20286765742076616c756520656e74727929290a20202020202020202865727220302929290a0a28646566696e652d7075626c696320287365742d76616c756520286b65792028627566662033322929202876616c75652028627566662033322929290a2020202028626567696e0a2020202020202020286d61702d7365742073746f72652028286b6579206b6579292920282876616c75652076616c75652929290a2020202020202020286f6b2027747275652929290a';

expect(serialized).toBe(tx);
});

test('Make smart contract deploy with clarity version 3', async () => {
const transaction = await makeContractDeploy({
contractName: 'kv-store',
codeBody: fs.readFileSync('./tests/contracts/kv-store.clar').toString(),
senderKey: 'e494f188c2d35887531ba474c433b1e41fadd8eb824aca983447fd4bb8b277a801',
clarityVersion: ClarityVersion.Clarity3,
fee: 0,
nonce: 0,
network: 'testnet',
});
expect(() => transaction.verifyOrigin()).not.toThrow();

const serialized = transaction.serialize();

expect(serialized[233]).toBe('3');

const tx =
'80800000000400e6c05355e0c990ffad19a5e9bda394a9c5003429000000000000000000000000000000000000d96e95cd80a14b294ab618061f886939c15a01692dff98a58e09310e8291cf3659ccb2b5fb98236ca74fd814fd51642f8287379f397262f266b41dda18773b860302000000000603086b762d73746f72650000015628646566696e652d6d61702073746f72652028286b657920286275666620333229292920282876616c7565202862756666203332292929290a0a28646566696e652d7075626c696320286765742d76616c756520286b65792028627566662033322929290a20202020286d6174636820286d61702d6765743f2073746f72652028286b6579206b65792929290a2020202020202020656e74727920286f6b20286765742076616c756520656e74727929290a20202020202020202865727220302929290a0a28646566696e652d7075626c696320287365742d76616c756520286b65792028627566662033322929202876616c75652028627566662033322929290a2020202028626567696e0a2020202020202020286d61702d7365742073746f72652028286b6579206b6579292920282876616c75652076616c75652929290a2020202020202020286f6b2027747275652929290a';

expect(serialized).toBe(tx);
});

test('Make smart contract deploy unsigned', async () => {
const contractName = 'kv-store';
const codeBody = fs.readFileSync('./tests/contracts/kv-store.clar').toString();
Expand Down

0 comments on commit 748e1e3

Please sign in to comment.