Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add RenounceOwnership message to OwnableTransferable trait #169

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- The `RenounceOwnership` message and its corresponding receiver were added to the `OwnableTransferable` trait allowing to transfer ownership to nobody

### Fixed

## [1.2.0] - 2024-02-29
Expand Down
8 changes: 4 additions & 4 deletions src/test/__snapshots__/bugs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ exports[`bugs should deploy contract correctly 1`] = `
"$type": "received",
"message": {
"body": {
"cell": "x{178D45190000000000000000502540BE400801D98D6D0FE85B55D6D58229C8ED55470B1C744D6BEEAD475C27236E9908A993110016E3A425A4E75B646191AC9A34FE5D050BD101A5C490F87D01C66D885D09BC1082_}",
"cell": "x{178D45190000000000000000502540BE400800CE4011EE2C736AE0658546CE43C9BC60CABD26F9E906C2E08F91925ED24B05BD0016E3A425A4E75B646191AC9A34FE5D050BD101A5C490F87D01C66D885D09BC1082_}",
"type": "cell",
},
"bounce": false,
"from": "kQDsxraH9C2q62rBFOR2qqOFjjomtfdWo64TkbdMhFTJiLsN",
"to": "kQBGSDIgoUMAjGBNBXjsdBRlfPtqK5rKgQOD5N7yKFfIXeuh",
"from": "kQBnIAj3Fjm1cDLCo2ch5N4wZV6TfPSDYXBHyMkvaSWC3ggs",
"to": "kQC6Vhi16Ku_T4BWi779yF6vlbp2J37fwovTpRR8DaacynWH",
"type": "internal",
"value": "9.95885",
},
Expand All @@ -38,7 +38,7 @@ exports[`bugs should deploy contract correctly 1`] = `
},
},
"bounce": false,
"from": "kQBGSDIgoUMAjGBNBXjsdBRlfPtqK5rKgQOD5N7yKFfIXeuh",
"from": "kQC6Vhi16Ku_T4BWi779yF6vlbp2J37fwovTpRR8DaacynWH",
"to": "@treasure(treasure)",
"type": "internal",
"value": "9.914852826",
Expand Down
246 changes: 246 additions & 0 deletions src/test/__snapshots__/feature-ownabletransferable.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`feature-ordering should deploy correctly 1`] = `
[
{
"$seq": 0,
"events": [
{
"$type": "deploy",
},
{
"$type": "received",
"message": {
"body": {
"text": "test",
"type": "text",
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"type": "internal",
"value": "1",
},
},
{
"$type": "processed",
"gasUsed": 4870n,
},
],
},
]
`;

exports[`feature-ordering should renounce ownership correctly 1`] = `
[
{
"$seq": 0,
"events": [
{
"$type": "deploy",
},
{
"$type": "received",
"message": {
"body": {
"text": "test",
"type": "text",
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"type": "internal",
"value": "1",
},
},
{
"$type": "processed",
"gasUsed": 4870n,
},
],
},
{
"$seq": 1,
"events": [
{
"$type": "storage-charged",
"amount": "0.000000006",
},
{
"$type": "received",
"message": {
"body": {
"type": "known",
"value": {
"$$type": "ChangeOwner",
"newOwner": kQAq4dsn8XD1ot3Hg_-nHdRkM5P1PaOZAy-YLG4p3mkQ96xD,
"queryId": 0n,
},
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"type": "internal",
"value": "1",
},
},
{
"$type": "processed",
"gasUsed": 8799n,
},
{
"$type": "sent",
"messages": [
{
"body": {
"type": "known",
"value": {
"$$type": "ChangeOwnerOk",
"newOwner": kQAq4dsn8XD1ot3Hg_-nHdRkM5P1PaOZAy-YLG4p3mkQ96xD,
"queryId": 0n,
},
},
"bounce": true,
"from": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"to": "@treasure(treasure)",
"type": "internal",
"value": "0.989738",
},
],
},
],
},
{
"$seq": 2,
"events": [
{
"$type": "storage-charged",
"amount": "0.000000006",
},
{
"$type": "received",
"message": {
"body": {
"type": "known",
"value": {
"$$type": "RenounceOwnership",
"queryId": 0n,
},
},
"bounce": true,
"from": "@treasure(anotherTreasure)",
"to": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"type": "internal",
"value": "1",
},
},
{
"$type": "processed",
"gasUsed": 11048n,
},
{
"$type": "sent",
"messages": [
{
"body": {
"type": "known",
"value": {
"$$type": "ChangeOwnerOk",
"newOwner": kQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHTW,
"queryId": 0n,
},
},
"bounce": true,
"from": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"to": "@treasure(anotherTreasure)",
"type": "internal",
"value": "0.987489",
},
],
},
],
},
]
`;

exports[`feature-ordering should transfer ownership correctly 1`] = `
[
{
"$seq": 0,
"events": [
{
"$type": "deploy",
},
{
"$type": "received",
"message": {
"body": {
"text": "test",
"type": "text",
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"type": "internal",
"value": "1",
},
},
{
"$type": "processed",
"gasUsed": 4870n,
},
],
},
{
"$seq": 1,
"events": [
{
"$type": "storage-charged",
"amount": "0.000000006",
},
{
"$type": "received",
"message": {
"body": {
"type": "known",
"value": {
"$$type": "ChangeOwner",
"newOwner": kQAq4dsn8XD1ot3Hg_-nHdRkM5P1PaOZAy-YLG4p3mkQ96xD,
"queryId": 0n,
},
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"type": "internal",
"value": "1",
},
},
{
"$type": "processed",
"gasUsed": 8799n,
},
{
"$type": "sent",
"messages": [
{
"body": {
"type": "known",
"value": {
"$$type": "ChangeOwnerOk",
"newOwner": kQAq4dsn8XD1ot3Hg_-nHdRkM5P1PaOZAy-YLG4p3mkQ96xD,
"queryId": 0n,
},
},
"bounce": true,
"from": "kQBGF0CUxwjQr65xgop8Bw8l5v1BfLn6Oey9WClezcq-HQ9z",
"to": "@treasure(treasure)",
"type": "internal",
"value": "0.989738",
},
],
},
],
},
]
`;
97 changes: 97 additions & 0 deletions src/test/feature-ownabletransferable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Address, toNano } from '@ton/core';
import { ContractSystem } from '@tact-lang/emulator';
import { __DANGER_resetNodeId } from '../grammar/ast';
import { OwnableTransferableTest } from './features/output/ownabletransferable_OwnableTransferableTest';

describe('feature-ordering', () => {
beforeEach(() => {
__DANGER_resetNodeId();
});
it('should deploy correctly', async () => {
// Init
const system = await ContractSystem.create();
const treasure = system.treasure('treasure');
const contract = system.open(
await OwnableTransferableTest.fromInit(treasure.address)
);
const tracker = system.track(contract.address);
await contract.send(treasure, { value: toNano('1') }, 'test');
await system.run();
expect(tracker.collect()).toMatchSnapshot();
expect(
(await contract.getOwner()).equals(treasure.address)
).toBeTruthy();
});

it('should transfer ownership correctly', async () => {
// Init
const system = await ContractSystem.create();
const treasure = system.treasure('treasure');
const contract = system.open(
await OwnableTransferableTest.fromInit(treasure.address)
);
const tracker = system.track(contract.address);
await contract.send(treasure, { value: toNano('1') }, 'test');
await system.run();
const anotherTreasure = system.treasure('anotherTreasure');
await contract.send(
treasure,
{ value: toNano('1') },
{
$$type: 'ChangeOwner',
newOwner: anotherTreasure.address,
queryId: 0n,
}
);
await system.run();
expect(tracker.collect()).toMatchSnapshot();
expect(
(await contract.getOwner()).equals(anotherTreasure.address)
).toBeTruthy();
});

it('should renounce ownership correctly', async () => {
// Init
const system = await ContractSystem.create();
const treasure = system.treasure('treasure');
const contract = system.open(
await OwnableTransferableTest.fromInit(treasure.address)
);
const tracker = system.track(contract.address);
await contract.send(treasure, { value: toNano('1') }, 'test');
await system.run();

const anotherTreasure = system.treasure('anotherTreasure');
await contract.send(
treasure,
{ value: toNano('1') },
{
$$type: 'ChangeOwner',
newOwner: anotherTreasure.address,
queryId: 0n,
}
);
await system.run();
expect(
(await contract.getOwner()).equals(anotherTreasure.address)
).toBeTruthy();

await contract.send(
anotherTreasure,
{ value: toNano('1') },
{
$$type: 'RenounceOwnership',
queryId: 0n,
}
);
await system.run();
expect(
(await contract.getOwner()).equals(
Address.parseRaw(
'0:0000000000000000000000000000000000000000000000000000000000000000'
)
)
).toBeTruthy();
expect(tracker.collect()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"OwnableTransferableTest","types":[{"name":"StateInit","header":null,"fields":[{"name":"code","type":{"kind":"simple","type":"cell","optional":false}},{"name":"data","type":{"kind":"simple","type":"cell","optional":false}}]},{"name":"Context","header":null,"fields":[{"name":"bounced","type":{"kind":"simple","type":"bool","optional":false}},{"name":"sender","type":{"kind":"simple","type":"address","optional":false}},{"name":"value","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"raw","type":{"kind":"simple","type":"slice","optional":false}}]},{"name":"SendParameters","header":null,"fields":[{"name":"bounce","type":{"kind":"simple","type":"bool","optional":false}},{"name":"to","type":{"kind":"simple","type":"address","optional":false}},{"name":"value","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"mode","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"body","type":{"kind":"simple","type":"cell","optional":true}},{"name":"code","type":{"kind":"simple","type":"cell","optional":true}},{"name":"data","type":{"kind":"simple","type":"cell","optional":true}}]},{"name":"Deploy","header":2490013878,"fields":[{"name":"queryId","type":{"kind":"simple","type":"uint","optional":false,"format":64}}]},{"name":"DeployOk","header":2952335191,"fields":[{"name":"queryId","type":{"kind":"simple","type":"uint","optional":false,"format":64}}]},{"name":"FactoryDeploy","header":1829761339,"fields":[{"name":"queryId","type":{"kind":"simple","type":"uint","optional":false,"format":64}},{"name":"cashback","type":{"kind":"simple","type":"address","optional":false}}]},{"name":"ChangeOwner","header":2174598809,"fields":[{"name":"queryId","type":{"kind":"simple","type":"uint","optional":false,"format":64}},{"name":"newOwner","type":{"kind":"simple","type":"address","optional":false}}]},{"name":"ChangeOwnerOk","header":846932810,"fields":[{"name":"queryId","type":{"kind":"simple","type":"uint","optional":false,"format":64}},{"name":"newOwner","type":{"kind":"simple","type":"address","optional":false}}]},{"name":"RenounceOwnership","header":472825648,"fields":[{"name":"queryId","type":{"kind":"simple","type":"uint","optional":false,"format":64}}]}],"receivers":[{"receiver":"internal","message":{"kind":"text","text":"test"}},{"receiver":"internal","message":{"kind":"typed","type":"ChangeOwner"}},{"receiver":"internal","message":{"kind":"typed","type":"RenounceOwnership"}}],"getters":[{"name":"owner","arguments":[],"returnType":{"kind":"simple","type":"address","optional":false}}],"errors":{"2":{"message":"Stack undeflow"},"3":{"message":"Stack overflow"},"4":{"message":"Integer overflow"},"5":{"message":"Integer out of expected range"},"6":{"message":"Invalid opcode"},"7":{"message":"Type check error"},"8":{"message":"Cell overflow"},"9":{"message":"Cell underflow"},"10":{"message":"Dictionary error"},"13":{"message":"Out of gas error"},"32":{"message":"Method ID not found"},"34":{"message":"Action is invalid or not supported"},"37":{"message":"Not enough TON"},"38":{"message":"Not enough extra-currencies"},"128":{"message":"Null reference exception"},"129":{"message":"Invalid serialization prefix"},"130":{"message":"Invalid incoming message"},"131":{"message":"Constraints error"},"132":{"message":"Access denied"},"133":{"message":"Contract stopped"},"134":{"message":"Invalid argument"},"135":{"message":"Code of a contract was not found"},"136":{"message":"Invalid address"},"137":{"message":"Masterchain support is not enabled for this contract"}},"interfaces":["org.ton.introspection.v0","org.ton.abi.ipfs.v0","org.ton.deploy.lazy.v0","org.ton.debug.v0","org.ton.chain.workchain.v0","org.ton.ownable.transferable.v3","org.ton.ownable"]}
Binary file not shown.
Loading
Loading