Skip to content

Commit 4a042be

Browse files
committed
avoid register network failure
1 parent d93eac9 commit 4a042be

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

contract-tests/src/subtensor.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as assert from "assert";
22
import { devnet, MultiAddress } from '@polkadot-api/descriptors';
3-
import { TypedApi, TxCallData, Binary, Enum } from 'polkadot-api';
3+
import { TypedApi, TxCallData, Binary, Enum, getTypedCodecs } from 'polkadot-api';
44
import { KeyPair } from "@polkadot-labs/hdkd-helpers"
55
import { getAliceSigner, waitForTransactionCompletion, getSignerFromKeypair, waitForTransactionWithRetry } from './substrate'
66
import { convertH160ToSS58, convertPublicKeyToSs58, ethAddressToH160 } from './address-utils'
77
import { tao } from './balance-math'
8-
import internal from "stream";
98

109
// create a new subnet and return netuid
1110
export async function addNewSubnetwork(api: TypedApi<typeof devnet>, hotkey: KeyPair, coldkey: KeyPair) {
11+
12+
1213
const alice = getAliceSigner()
1314
const totalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue()
1415

@@ -26,6 +27,9 @@ export async function addNewSubnetwork(api: TypedApi<typeof devnet>, hotkey: Key
2627
const newTotalNetworks = await api.query.SubtensorModule.TotalNetworks.getValue()
2728
// could create multiple subnetworks during retry, just return the first created one
2829
assert.ok(newTotalNetworks > totalNetworks)
30+
31+
await resetNetworkLastLock(api)
32+
2933
return totalNetworks
3034
}
3135

@@ -398,4 +402,21 @@ export async function sendWasmContractExtrinsic(api: TypedApi<typeof devnet>, co
398402
storage_deposit_limit: BigInt(1000000000)
399403
})
400404
await waitForTransactionWithRetry(api, tx, signer)
401-
}
405+
}
406+
407+
export async function resetNetworkLastLock(api: TypedApi<typeof devnet>) {
408+
const alice = getAliceSigner()
409+
const key = await api.query.SubtensorModule.NetworkLastLockCost.getKey()
410+
411+
// Get the codec for NetworkLastLockCost value (TaoCurrency/u128)
412+
const codec = await getTypedCodecs(devnet)
413+
const valueCodec = codec.query.SubtensorModule.NetworkLastLockCost.value
414+
415+
// Encode the value (0) as SCALE-encoded bytes
416+
const encodedValue = valueCodec.enc(BigInt(0))
417+
418+
const changes: [Binary, Binary][] = [[Binary.fromHex(key.toString()), Binary.fromBytes(encodedValue)]];
419+
const internalCall = api.tx.System.set_storage({ items: changes })
420+
const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall })
421+
await waitForTransactionWithRetry(api, tx, alice)
422+
}

0 commit comments

Comments
 (0)