-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert: reinstates the tests using the node on port 3030
- Loading branch information
1 parent
6640652
commit 2d054e0
Showing
16 changed files
with
193 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const NETWORK_ID = 'sandbox'; | ||
export const NETWORK_ID = 'localnet'; | ||
export const NODE_URL = 'http://localhost:3030'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Account, connect, keyStores, utils } from 'near-api-js'; | ||
import { resolve } from 'node:path'; | ||
import { cwd } from 'node:process'; | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
// constants | ||
import { NETWORK_ID, NODE_URL } from './constants'; | ||
|
||
// credentials | ||
import { account_id as genesisAccountId } from './credentials/localnet/test.near.json'; | ||
import { account_id as socialContractAccountId } from './credentials/localnet/social.test.near.json'; | ||
|
||
// helpers | ||
import createTestAccount from './helpers/createTestAccount'; | ||
|
||
// utils | ||
import convertNEARToYoctoNEAR from '../src/utils/convertNEARToYoctoNEAR'; | ||
|
||
export default async function globalSetup() { | ||
const _functionName = 'globalSetup'; | ||
const near = await connect({ | ||
networkId: NETWORK_ID, | ||
nodeUrl: NODE_URL, | ||
keyStore: new keyStores.UnencryptedFileSystemKeyStore( | ||
resolve(cwd(), 'test', 'credentials') | ||
), | ||
}); | ||
const contract = await readFile( | ||
resolve(cwd(), 'test', 'contracts', 'social_db.wasm') | ||
); | ||
let contractAccountPublicKey: utils.PublicKey; | ||
let contractAccount: Account; | ||
let genesisAccount: Account; | ||
|
||
genesisAccount = await near.account(genesisAccountId); | ||
contractAccountPublicKey = await near.connection.signer.getPublicKey( | ||
socialContractAccountId, | ||
NETWORK_ID | ||
); | ||
|
||
// create the contract account | ||
contractAccount = await createTestAccount({ | ||
creatorAccount: genesisAccount, | ||
initialBalanceInAtomicUnits: BigInt(convertNEARToYoctoNEAR('10')), | ||
newAccountID: socialContractAccountId, | ||
newAccountPublicKey: contractAccountPublicKey, | ||
connection: near, | ||
}); | ||
|
||
// deploy the account | ||
await contractAccount.deployContract(contract); | ||
|
||
try { | ||
// initialize the contract | ||
await genesisAccount.functionCall({ | ||
contractId: contractAccount.accountId, | ||
methodName: 'new', | ||
}); | ||
// set the contract to live | ||
await contractAccount.functionCall({ | ||
contractId: contractAccount.accountId, | ||
methodName: 'set_status', | ||
args: { | ||
status: 'Live', | ||
}, | ||
}); | ||
} catch (error) { | ||
// if the contract has already been initialized, just ignore | ||
if (error.message.includes('The contract has already been initialized')) { | ||
return; | ||
} | ||
|
||
console.error(`${_functionName}:`, JSON.stringify(error)); | ||
} | ||
} |
Oops, something went wrong.