NEW YORK, June 7 (Reuters) - U.S. stocks rose on Wednesday despite a sharp decline in energy shares after written testimony from former FBI director James Comey did not add major revelations about an investigation into Russian meddling with last year’s U.S. presidential election.

Comey, who was fired by Trump last month, wrote that U.S. President Donald Trump asked him to drop an investigation of former national security adviser Michael Flynn.

But the details of Comey’s testimony, expected to be delivered Thursday to a Senate Committee, appeared to be priced into the stock market.

Investors were concerned that any additional revelation could dampen already flagging momentum for Trump’s agenda of lower taxes and lax regulations.

Bets that Trump can implement his agenda are partly behind a rally that has taken stock indexes to record highs.

“They were hoping that there wasn’t going to be anything in there that was more inflammatory,” said Peter Costa, president of trading firm Empire Executions.

“The testimony wasn’t as disastrous as it could have been,” he said of the prepared remarks, adding that the market was relieved no damaging details emerged and his testimony “more than likely isn’t going to blow up into some big fiasco, another thing that the president has to deal with.”

Costa cautioned that the market’s reaction to Comey’s remarks was not a particularly big move up and volume was light.

The Dow Jones Industrial Average rose 37.46 points, or 0.18 percent, to 21,173.69, the S&P 500 gained 3.81 points, or 0.16 percent, to 2,433.14 and the Nasdaq Composite added 22.32 points, or 0.36 percent, to 6,297.38.

Wall Street was weighed by a near 2-percent drop in the S&P 500’s energy sector. All but two of the 34 components of the sector fell as U.S. crude futures tumbled 5 percent due to an unexpected rise in U.S. inventories. Brent crude fell nearly 4 percent.

The largest percentage gainer on the S&P 500 was Signet Jewelers, which rose 4 percent, while the largest decliner was Newfield Exploration, down 7 percent.

Investors are also keeping an eye on Britain’s general election and the European Central Bank’s policy meeting, both on Thursday.

Opinion polls have shown Conservative Prime Minister Theresa May’s lead over the opposition Labor party narrow over the last three weeks, with some even suggesting she could fall short of a majority government. The election comes as Britain maps its exit from the European Union following a referendum on the subject last year.

The ECB is expected to reiterate its plan to maintain a very accommodative monetary policy at least until the end of the year.

Declining issues outnumbered advancing ones on the NYSE by a 1.12-to-1 ratio; on Nasdaq, a 1.13-to-1 ratio favored advancers.

Volume on U.S. exchanges was 6.60 billion shares, roughly in line with the average over the last 20 trading days. (Reporting by Rodrigo Campos, additional reporting by Tanya Agrawal in Bengaluru and Lewis Krauskopf in New York; Editing by Nick Zieminski)