@@ -2,11 +2,9 @@ import * as anchor from "@coral-xyz/anchor";
22import { SolAnchorContract } from "../target/types/sol_anchor_contract" ;
33
44describe ( "sol-anchor-contract" , ( ) => {
5- const fs = require ( "fs" ) ;
6- const assert = require ( "assert" ) ;
75
8- let ethToUSD = "EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw" ;
9- let usdtToUSD = "38xoQ4oeJCBrcVvca2cGk7iV1dAfrmTR1kmhSCJQ8Jto" ;
6+ const ethToUSD = "EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw" ;
7+ const usdtToUSD = "38xoQ4oeJCBrcVvca2cGk7iV1dAfrmTR1kmhSCJQ8Jto" ;
108
119 const provider = anchor . AnchorProvider . local ( ) ;
1210
@@ -17,18 +15,14 @@ describe("sol-anchor-contract", () => {
1715 const program = anchor . workspace
1816 . SolAnchorContract as anchor . Program < SolAnchorContract > ;
1917 const payer = provider . wallet . publicKey ;
20- let programId = program . programId ;
21- const programKey = program . programId ;
22- console . log ( programKey )
23-
18+
2419 it ( "Initialize the config." , async ( ) => {
2520 const tx = await program . methods
2621 . init ( {
2722 loanPriceFeedId : new anchor . web3 . PublicKey ( ethToUSD ) ,
2823 collateralPriceFeedId : new anchor . web3 . PublicKey ( usdtToUSD ) ,
2924 } )
3025 . accounts ( {
31- program : programId ,
3226 payer,
3327 config : config . publicKey ,
3428 systemProgram : anchor . web3 . SystemProgram . programId ,
@@ -54,30 +48,4 @@ describe("sol-anchor-contract", () => {
5448 console . log ( "Loan2Value() is invoked: " + tx ) ;
5549 } ) ;
5650
57- it ( "Prevent initialization of config without authority." , async ( ) => {
58- const attacker = anchor . web3 . Keypair . generate ( ) ;
59-
60- var tx ,
61- success = false ;
62- try {
63- tx = await program . methods
64- . init ( {
65- loanPriceFeedId : new anchor . web3 . PublicKey ( ethToUSD ) ,
66- collateralPriceFeedId : new anchor . web3 . PublicKey ( usdtToUSD ) ,
67- } )
68- . accounts ( {
69- program : programId ,
70- payer,
71- config : config . publicKey ,
72- systemProgram : anchor . web3 . SystemProgram . programId ,
73- } )
74- . signers ( [ config , attacker ] )
75- . rpc ( ) ;
76-
77- success = true ;
78- } catch ( error ) {
79- console . log ( "Attacker failed at unauthorized init" ) ;
80- }
81- if ( success ) throw new Error ( "Attacker succeeded! TxHash: " + tx ) ;
82- } ) ;
8351} ) ;
0 commit comments