Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tolk 1.0

struct (0x00000001) SelfDestruct {
queryId: uint64,
}

type SelfDestruct_InMessage = SelfDestruct;

fun onInternalMessage(in: InMessage) {
val msg = lazy SelfDestruct_InMessage.fromSlice(in.body);
match (msg) {
SelfDestruct => {
val reply = createMessage({
bounce: false,
value: 0,
dest: in.senderAddress,
body: beginCell().endCell(),
});
reply.send(SEND_MODE_CARRY_ALL_BALANCE + SEND_MODE_DESTROY);
}
else => {
assert (in.body.isEmpty()) throw 0xFFFF;
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CompilerConfig } from '@ton/blueprint'

export const compile: CompilerConfig = {
lang: 'tolk',
entrypoint: 'contracts/test/examples/async-communication/self_destructable.tolk',
withStackComments: true, // Fift output will contain comments, if you wish to debug its output
experimentalOptions: '', // you can pass experimental compiler options here
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package sendmodedestroy

import (
"fmt"
"math/rand/v2"

"github.com/xssnick/tonutils-go/tlb"
"github.com/xssnick/tonutils-go/tvm/cell"

"github.com/smartcontractkit/chainlink-ton/pkg/bindings"
"github.com/smartcontractkit/chainlink-ton/pkg/ton/tracetracking"
"github.com/smartcontractkit/chainlink-ton/pkg/ton/wrappers"
)

var SelfDestroyContractPath = bindings.GetBuildDir("examples.async-communication.send-mode-destroy.SelfDestructable.compiled.json")

type SelfDestroyProvider struct {
apiClient tracetracking.SignedAPIClient
}

func NewSelfDestructableProvider(apiClient tracetracking.SignedAPIClient) *SelfDestroyProvider {
return &SelfDestroyProvider{
apiClient: apiClient,
}
}

type SelfDestroyInitData struct {
}

func (p *SelfDestroyProvider) Deploy(initData SelfDestroyInitData) (SelfDestroy, error) {
initDataCell, err := tlb.ToCell(wrappers.LazyLoadingTactContractInitData(initData))
if err != nil {
return SelfDestroy{}, fmt.Errorf("failed to serialize init data: %w", err)
}
compiledContract, err := wrappers.ParseCompiledContract(SelfDestroyContractPath)
if err != nil {
return SelfDestroy{}, fmt.Errorf("failed to compile contract: %w", err)
}
body := cell.BeginCell().EndCell()
contract, _, err := wrappers.Deploy(&p.apiClient, compiledContract, initDataCell, tlb.MustFromTON("1"), body)
if err != nil {
return SelfDestroy{}, err
}

return SelfDestroy{
Contract: *contract,
}, nil
}

type SelfDestroy struct {
Contract wrappers.Contract
}

type SendSelfDestructMessage struct {
_ tlb.Magic `tlb:"#00000001"` //nolint:revive // (opcode) should stay uninitialized
QueryID uint64 `tlb:"## 64"`
}

func (c SelfDestroy) SendSelfDestruct() (msgReceived *tracetracking.ReceivedMessage, err error) {
queryID := rand.Uint64()
msgReceived, err = c.Contract.CallWaitRecursively(SendSelfDestructMessage{
QueryID: queryID,
}, tlb.MustFromTON("0.5"))
return msgReceived, err
}
17 changes: 16 additions & 1 deletion integration-tests/tracetracking/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/smartcontractkit/chainlink-ton/integration-tests/tracetracking/async/wrappers/requestreply"
"github.com/smartcontractkit/chainlink-ton/integration-tests/tracetracking/async/wrappers/requestreplywithtwodependencies"
"github.com/smartcontractkit/chainlink-ton/integration-tests/tracetracking/async/wrappers/sendmodedestroy"
"github.com/smartcontractkit/chainlink-ton/integration-tests/tracetracking/async/wrappers/twomsgchain"
"github.com/smartcontractkit/chainlink-ton/integration-tests/tracetracking/async/wrappers/twophasecommit"

Expand All @@ -35,7 +36,7 @@ func TestIntegration(t *testing.T) {
}

var initialAmount = big.NewInt(1_000_000_000_000)
var accountCount uint = 13
var accountCount uint = 14
accounts := testutils.SetUpTest(t, chainsel.TON_LOCALNET.Selector, initialAmount, accountCount)
var lastUsedAccountIndex uint
var accountsLock sync.Mutex
Expand Down Expand Up @@ -613,4 +614,18 @@ func TestIntegration(t *testing.T) {

t.Logf("Test completed successfully\n")
})

t.Run("TestSelfDestructContract", func(t *testing.T) {
t.Parallel()
alice := getAccount()
t.Logf("\n\n\n\n\n\nTestStarted\n==========================\n")
t.Logf("Deploying SelfDestructable contract\n")
selfDestructableContract, err := sendmodedestroy.NewSelfDestructableProvider(alice).Deploy(sendmodedestroy.SelfDestroyInitData{})
require.NoError(t, err, "failed to deploy SelfDestruct contract: %w", err)
t.Logf("SelfDestruct contract deployed at %s\n", selfDestructableContract.Contract.Address.String())

t.Logf("Calling selfdestruct\n")
_, err = selfDestructableContract.SendSelfDestruct()
require.NoError(t, err, "failed to call selfdestruct: %w", err)
})
}
Loading