Skip to content

Commit 082db6f

Browse files
script to deploy test receiver (#436)
* script to deploy test receiver * update readme * remove comment * fmt * fix runtime importing @jest/globals * add .env to gitignore * fmt * Update contracts/scripts/README.md Co-authored-by: Juan Farber <[email protected]> * Update contracts/scripts/deployReceiver.ts Co-authored-by: Juan Farber <[email protected]> * Update contracts/scripts/deployReceiver.ts Co-authored-by: Juan Farber <[email protected]> * Update contracts/scripts/deployReceiver.ts Co-authored-by: Juan Farber <[email protected]> * fix router addr instead of offramp addr * fix routeraddr --------- Co-authored-by: Juan Farber <[email protected]>
1 parent 96b36ae commit 082db6f

File tree

8 files changed

+103
-3
lines changed

8 files changed

+103
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ _vendor/
4848

4949
# Binary
5050
cmd/chainlink-ton/chainlink-ton
51+
52+
.env

contracts/.env_example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
WALLET_MNEMONIC="word1 word2 ... word24"
3+
WALLET_VERSION="v4R2" # or v4, v5r1, etc
4+
# optionally:
5+
# WALLET_ID="123456"
6+
# SUBWALLET_NUMBER="0"

contracts/jest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const config: Config = {
2323
workerThreads: true,
2424

2525
testTimeout: 30000, // Overwrite default 5s timeout
26+
27+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
2628
}
2729

2830
export default config

contracts/jest.setup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { expect } from '@jest/globals'
2+
import { tonEquals } from './src/utils'
3+
4+
expect.addEqualityTesters([tonEquals])

contracts/scripts/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Run scripts with `yarn blueprint run`, [configure your wallet mnemonic on a .env file](https://github.com/ton-org/blueprint#using-mnemonic-provider)
2+
3+
```
4+
yarn blueprint run deployReceiver --testnet --mnemonic RouterAddr...
5+
yarn blueprint run updateReceiverBehavior --testnet --mnemonic ReceiverAddr... RejectAll
6+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Address, toNano } from '@ton/core'
2+
import { compile, NetworkProvider } from '@ton/blueprint'
3+
import { Receiver, ReceiverBehavior } from '../wrappers/ccip/Receiver'
4+
import { generateRandomContractId } from '../src/utils'
5+
6+
export async function run(provider: NetworkProvider, args: string[]) {
7+
const [routerRaw] = args
8+
9+
if (!routerRaw) {
10+
throw new Error(
11+
'Usage: yarn blueprint run deployReceiver --<network> --mnemonic <routerAddress>',
12+
)
13+
}
14+
15+
const routerAddress = Address.parse(routerRaw)
16+
17+
const receiverAddress = await deployReceiver(provider, routerAddress)
18+
19+
console.log('✅ Receiver deployed at:', receiverAddress.toString())
20+
}
21+
22+
export async function deployReceiver(
23+
provider: NetworkProvider,
24+
routerAddress: Address,
25+
): Promise<Address> {
26+
const deployer = provider.sender().address!
27+
const receiver = provider.open(
28+
Receiver.createFromConfig(
29+
{
30+
id: generateRandomContractId(),
31+
behavior: ReceiverBehavior.RejectAll,
32+
ownable: {
33+
owner: deployer,
34+
pendingOwner: null,
35+
},
36+
authorizedCaller: routerAddress,
37+
},
38+
await compile('ccip.test.receiver'),
39+
),
40+
)
41+
42+
await receiver.sendDeploy(provider.sender(), toNano('0.5'))
43+
await provider.waitForDeploy(receiver.address)
44+
return receiver.address
45+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Address, toNano } from '@ton/core'
2+
import { NetworkProvider } from '@ton/blueprint'
3+
import { Receiver, ReceiverBehavior } from '../wrappers/ccip/Receiver'
4+
5+
export async function run(provider: NetworkProvider, args: string[]) {
6+
const [receiverRaw, behaviorRaw] = args
7+
8+
if (!receiverRaw || !behaviorRaw) {
9+
throw new Error(
10+
'Usage: yarn blueprint run updateReceiverBehavior --<network> --mnemonic <receiverAddress> <behavior>',
11+
)
12+
}
13+
14+
const receiver = Address.parse(receiverRaw)
15+
16+
// Map string -> enum value
17+
const behavior = (ReceiverBehavior as any)[behaviorRaw as keyof typeof ReceiverBehavior]
18+
19+
if (behavior === undefined) {
20+
throw new Error(
21+
`Unknown behavior "${behaviorRaw}". Valid values: ${Object.keys(ReceiverBehavior).join(', ')}`,
22+
)
23+
}
24+
25+
await updateReceiverBehavior(provider, receiver, behavior)
26+
27+
console.log(`✅ Updated receiver ${receiver.toString()} behavior to ${behaviorRaw}`)
28+
}
29+
30+
async function updateReceiverBehavior(
31+
provider: NetworkProvider,
32+
receiver: Address,
33+
behavior: ReceiverBehavior,
34+
) {
35+
const receiverContract = provider.open(Receiver.createFromAddress(receiver))
36+
await receiverContract.sendUpdateBehavior(provider.sender(), toNano('0.05'), { behavior })
37+
}

contracts/src/utils/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function hashSync(data: string): bigint {
9898
return uint8ArrayToBigInt(sha256_sync(data))
9999
}
100100

101-
function tonEquals(a, b) {
101+
export function tonEquals(a, b) {
102102
if (a instanceof Address) {
103103
if (!(b instanceof Address)) return false
104104
return a.equals(b)
@@ -161,9 +161,7 @@ export function generateRandomMockSigners(count: number) {
161161
}
162162

163163
// Extend expect to support Address and Cell equality
164-
import { expect } from '@jest/globals'
165164
import { WalletContractV4 } from '@ton/ton'
166-
expect.addEqualityTesters([tonEquals])
167165

168166
export function generateRandomContractId(): bigint {
169167
return BigInt(Math.floor(Math.random() * 0x100000000)) // 2^32

0 commit comments

Comments
 (0)