In the months before he was arrested, Ismael Habib, 29, was the subject of multiple undercover sting operations, Quebec Court Judge Serge Délisle heard Tuesday.

The prosecution, led by federal Crown prosecutor Lyne Décarie, called on two undercover RCMP officers involved in those operations to testify on the second day of Habib's trial.

Habib, represented by defence lawyer Charles Montpetit, is accused of trying to leave the country to commit terrorist acts and giving false information to obtain a passport.

Box of fake passports

To protect their identity, the undercover officers testified from behind a partition in court.

One agent testified that after building the accused's trust over a period of time, he travelled with Habib to Bainsville, Ont., just over the Quebec-Ontario border, with a box of fake passports.

He said he met Habib and took him to government offices in downtown Montreal, where a second undercover agent approached the car with a shoebox in a bag.

When they opened the bag, there were three blank passports inside.

The agent drove with Habib to Bainsville, where they met a third undercover agent to whom they handed the box of blank passports.

According to testimony, on the way to Ontario, Habib told the agent he'd paid $1,800 to obtain a passport in the past.

During the trip, the agent and Habib stopped to eat at a St. Hubert restaurant. Over poutine, Habib told the officer he liked Canada a lot, saying the laws are less strict than in the U.S., and he appreciated the child benefit payments he received from the government.

"We make kids, we get money," he allegedly said.

On watch list since 2013

The court learned Habib has been under police surveillance since at least September 2015, more than one year after he allegedly tried to get a passport under the name of his brother, Sammy Mohammed Habib.

Ismael Habib had been on Passport Canada's watch list since March 2013, when he came under suspicion of terrorist activities.

Despite being on the watch list, he travelled to Turkey in November of that year, where he was arrested by Turkish authorities who seized his passport.

Testimony shows there were at least five undercover officers involved in trying to catch Habib for committing a crime.

Ultimately, he was arrested late last February in an alleged domestic altercation with a woman he was involved with in Gatineau. In a separate case, Habib is charged with uttering death threats, criminal harassment and identity fraud.

After he was detained on those charges, Habib was transferred to Montreal to be charged with the terrorism-related offence.

Found Allah after bad drug trip

In earlier years, Habib used cocaine and amphetamines, a second undercover agent testified. That agent outlined one experience where Habib had taken hard drugs four days in a row.

"He was really sick. Couldn't breathe. Thought he'd die. He looked outside and asked God to save him. And if Allah saved him, he would dedicate his life to Allah," the agent recounted.

Algeria or Syria?

A key element in the trial is whether Habib was hoping to travel to Algeria or Syria. His wife and two children initially lived in Algeria, however, his ex-girlfriend testified he wanted to meet her in Syria and fight with ISIS there.

During cross-examination, the first undercover agent acknowledged Habib told him he hoped to go to Algeria, not Syria.